У меня есть такое правило
Код: Выделить всё
class NotNumberRule implements ValidationRule
{
/**
* Run the validation rule.
*
* @param string $attribute
* @param mixed $value
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (is_numeric($value)) {
$fail('error');
return;
}
}
}
Код: Выделить всё
foreach ($rules as $rule) {
$rule = new ($rule);
if ($rule instanceof ValidationRule) {
// I don't know how to get result of rule and the message of rule
}
if (
$rule instanceof Rule &&
!$rule->passes($setting->field, $value)
) {
throw ValidationException::withMessages([$setting->field => $rule->message()]);
}
}
Подробнее здесь: https://stackoverflow.com/questions/767 ... dationrule
Мобильная версия