41 lines
950 B
PHP
41 lines
950 B
PHP
<?php
|
|
|
|
namespace App\Rules\Sigtap;
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ProcedimentoIsValidForIdade implements Rule
|
|
{
|
|
private $idade;
|
|
|
|
public function __construct($idade)
|
|
{
|
|
$this->idade = $idade;
|
|
}
|
|
|
|
public function passes($attribute, $value)
|
|
{
|
|
return self::isValid($this->idade, $value);
|
|
}
|
|
|
|
public static function isValid($idade, $value)
|
|
{
|
|
$idade *= 12;
|
|
|
|
$procedimento = DB::table('sigtap.procedimento')
|
|
->where('id', $value)
|
|
->select('idade_minima', 'idade_maxima')
|
|
->first();
|
|
|
|
return
|
|
($idade >= $procedimento->idade_minima || $procedimento->idade_minima === 9999) &&
|
|
($idade <= $procedimento->idade_maxima || $procedimento->idade_maxima === 9999);
|
|
}
|
|
|
|
public function message()
|
|
{
|
|
return 'Procedimento inválido para a idade informada.';
|
|
}
|
|
}
|