ManagementSystem/BACKEND/Modules/Admin/app/Rules/PercentRule.php

31 lines
646 B
PHP
Executable File

<?php
namespace Modules\Admin\app\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
class PercentRule implements ValidationRule
{
static public function check($value): bool
{
$percent = (float) $value;
return ((1 <= $percent) && ($percent <= 99));
}
static public function message(): string
{
return 'The percent must be from 1% to 100%.';
}
/**
* Run the validation rule.
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (!$this->check($value)) {
$fail($this->message());
}
}
}