【发布时间】:2019-03-17 14:23:41
【问题描述】:
是否可以在自定义规则中使用现有的 Laravel 验证规则?
示例:required|string|max:100 我只想将这些规则归为一条规则custom_rule_name。
不管怎样
Validator::extend('foo', function ($attribute, $value, $parameters, $validator) {
return $value == 'required|string|max:100';//something like this
});
或
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class Uppercase implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return $value == 'required|string|max:100';//something like this
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'The :attribute must be uppercase.';
}
}
如果有可能,请告诉我?
谢谢,
卡莱姆
【问题讨论】:
标签: php laravel laravel-5 laravel-validation