欢迎各位兄弟 发布技术文章
这里的技术是共享的
public function boot() {// Validator::extend('mobile', function($attribute, $value, $parameters) { //return preg_match('/^1[34578][0-9]{9}$/', $value);
return preg_match('/^1[0123456789][0-9]{9}$/', $value); }); }
return Validator::make($data, [ 'name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|confirmed|min:6', //下面增加这一行 'tel'=>'required|size:11|mobile' ]);
或者在 app/Http/Requests/OrderRequest.php 里面添加验证规则
public function authorize()
{
return true;
}
public function rules()
{
return [
//
'customer_name'=>'required',
'customer_tel'=>'required|mobile',
'customer_email'=>'required',
];
}
'mobile' => " 电话号码不对。",
如下的样子'attribute-name' => [ 'rule-name' => 'custom-message', ], 'theme_title' => [ 'required' => '模板名称不能为空', ], 'theme_url' => [ 'required' => '模板网址不能为空', ], 'baike_title' => [ 'required' => '百科名称不能为空', ], 'baike_net_url' => [ 'required' => '百科对应网址不能为空', 'url' =>'百科对应网址格式不对', ], ],
'attributes' => [],
I would like to write a function in my FormRequest object to perform some custom validation steps in Laravel 5, but I can't seem to find a function to override/implement to perform these steps. What is the best approach to do something like that?