This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules\Cadastro\SujeitoAtencao;
|
||||
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class PacienteRequireEndereco implements Rule
|
||||
{
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
return Paciente::where('id', $value)
|
||||
->whereHas('cidadao.domicilio.endereco', function($query) {
|
||||
$query->whereNotNull('numero');
|
||||
})
|
||||
->whereHas('cidadao.domicilio.endereco.logradouro', function($query) {
|
||||
$query->has('municipio')
|
||||
->has('bairro')
|
||||
->has('tipo')
|
||||
->whereNotNull('nome')
|
||||
->whereNotNull('cep');
|
||||
})->exists();
|
||||
}
|
||||
|
||||
public function message()
|
||||
{
|
||||
return 'Endereço inconsistente para o paciente selecionado.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user