parfum/app/Rules/UnsignedInteger.php

23 lines
539 B
PHP

<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
class UnsignedInteger implements ValidationRule
{
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (! ctype_digit((string) $value)) {
$fail("{$attribute} harus berupa bilangan bulat positif.");
return;
}
if ((int) $value < 0 || (int) $value > 4294967295) {
$fail("{$attribute} harus berada di antara 0 dan 4294967295.");
}
}
}