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