cidId = $cidId; } public function passes($attribute, $value) { return self::isValid($this->cidId, $value); } public static function isValid($cidId, $value) { $procedimentoRequerCid = DB::table('sigtap.procedimento')->where('id', $value) ->whereExists(function ($query) { $query->select(DB::raw(1)) ->from('sigtap.procedimento_cid') ->whereColumn('sigtap.procedimento_cid.procedimento_id', 'sigtap.procedimento.id') ->where('principal', 'S'); })->exists(); if($procedimentoRequerCid){ $cidValidoParaProceidmento = DB::table('sigtap.procedimento')->where('id', $value) ->whereExists(function ($query) use ($cidId) { $query->select(DB::raw(1)) ->from('sigtap.procedimento_cid') ->whereColumn('sigtap.procedimento_cid.procedimento_id', 'sigtap.procedimento.id') ->where('sigtap.procedimento_cid.cid_id', $cidId); }) ->exists(); if($cidValidoParaProceidmento){ return true; }else{ return false; } }else{ return true; } } public function message() { return 'Procedimento inválido para o CID informado.'; } }