2021-06-20 13:03:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Rules;
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
|
2024-04-12 05:29:11 +00:00
|
|
|
use App\Models\Address;
|
2021-06-20 13:03:20 +00:00
|
|
|
|
|
|
|
class TwoByteInteger implements Rule
|
|
|
|
{
|
2022-01-15 02:06:15 +00:00
|
|
|
/**
|
|
|
|
* Determine if the validation rule passes.
|
2024-04-12 05:29:11 +00:00
|
|
|
* This will check that a number used for zone, net, host is between 1 and Address::ADDRESS_FIELD_MAX.
|
2022-01-15 02:06:15 +00:00
|
|
|
*
|
2023-06-27 07:39:11 +00:00
|
|
|
* @param string $attribute
|
|
|
|
* @param mixed $value
|
2022-01-15 02:06:15 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function passes($attribute,$value)
|
|
|
|
{
|
2024-04-12 05:29:11 +00:00
|
|
|
return (is_numeric($value) && ($value > 0) && ($value < Address::ADDRESS_FIELD_MAX));
|
2022-01-15 02:06:15 +00:00
|
|
|
}
|
2021-06-20 13:03:20 +00:00
|
|
|
|
2022-01-15 02:06:15 +00:00
|
|
|
/**
|
|
|
|
* Get the validation error message.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function message()
|
|
|
|
{
|
2024-04-12 05:29:11 +00:00
|
|
|
return sprintf('The number must be between 1 and %d.',Address::ADDRESS_FIELD_MAX);
|
2022-01-15 02:06:15 +00:00
|
|
|
}
|
2023-06-27 07:39:11 +00:00
|
|
|
}
|