32 lines
760 B
PHP
32 lines
760 B
PHP
<?php
|
|
|
|
namespace App\Rules\AtencaoBasica\Exportacao;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
class DataNascimentoIsValid implements Rule
|
|
{
|
|
public function passes($attribute, $value)
|
|
{
|
|
return self::isValid($value);
|
|
}
|
|
|
|
public static function isValid($value)
|
|
{
|
|
|
|
$dataAtendimento = Carbon::parse($value['data_atendimento']);
|
|
$dataNascimentoPaciente = Carbon::parse($value['data_nascimento']);
|
|
|
|
$limiteInferior = $dataAtendimento->copy()->subYears(130);
|
|
$limiteSuperior = $dataAtendimento->copy();
|
|
|
|
return $dataNascimentoPaciente->isBetween($limiteInferior, $limiteSuperior);
|
|
}
|
|
|
|
public function message()
|
|
{
|
|
return 'Data de nascimento inválida';
|
|
}
|
|
}
|