44 lines
1.0 KiB
PHP
44 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Rules\Sigtap\Procedimento;
|
|
|
|
use App\Models\Sigtap\Procedimento;
|
|
use App\Services\Sigtap\ProcedimentoValidationService;
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
class Quantidade implements Rule
|
|
{
|
|
private Procedimento $procedimento;
|
|
private ?int $quantidade;
|
|
|
|
public function __construct(Procedimento $procedimento, ?int $quantidade = null)
|
|
{
|
|
$this->procedimento = $procedimento;
|
|
$this->quantidade = $quantidade;
|
|
}
|
|
|
|
/**
|
|
* Determine if the validation rule passes.
|
|
*
|
|
* @param string $attribute
|
|
* @param mixed $value
|
|
* @return bool
|
|
*/
|
|
public function passes($attribute, $value)
|
|
{
|
|
$validation = new ProcedimentoValidationService($this->procedimento);
|
|
|
|
return $validation->isQuantidadeValid($this->quantidade ?? $value);
|
|
}
|
|
|
|
/**
|
|
* Get the validation error message.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function message()
|
|
{
|
|
return "Quantidade máxima atingida para o :attribute";
|
|
}
|
|
}
|