ldc-dam/app/Rules/IsValidRole.php

37 lines
861 B
PHP
Raw Normal View History

2022-03-28 17:43:52 +02:00
<?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
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
2022-03-28 17:43:52 +02:00
*/
public function passes($attribute, $value)
{
// phpcs:enable
2022-03-28 17:43:52 +02:00
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.';
}
}