34 lines
766 B
PHP
34 lines
766 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
class IsValidRole implements Rule
|
|
{
|
|
/**
|
|
* Determine if the validation rule passes.
|
|
*
|
|
* @param mixed $attribute
|
|
* @param mixed $value
|
|
* @return boolean
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed
|
|
*/
|
|
public function passes($attribute, $value)
|
|
{
|
|
if (!\ctype_digit(strval($value))) {
|
|
return false;
|
|
};
|
|
return in_array(\strval($value), config('roles.const'));
|
|
}
|
|
|
|
/**
|
|
* Get the validation error message.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function message()
|
|
{
|
|
return 'L\'attribut :attribute n\'est pas valide.';
|
|
}
|
|
}
|