unidadeId = $unidadeId; $this->competenciaId = $competenciaId; } public function passes($attribute, $value) { $response = true; Exportacao::where('unidade_id', $this->unidadeId) ->where('competencia_id', $this->competenciaId) ->whereHas('financiamentos', function($query) use ($value) { $query->from('sigtap.financiamento')->whereIn('id', $value); }) ->get() ->map(function($exportacao) use ($value, &$response) { if ($exportacao->financiamentos->count() === count($value)) { $response = false; } }); return $response; } public function message() { return 'Exportação já existente para os financiamentos selecionados.'; } }