This commit is contained in:
43
api/app/Rules/Sigtap/Procedimento/Quantidade.php
Normal file
43
api/app/Rules/Sigtap/Procedimento/Quantidade.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user