我正试图将这些验证规则应用于我的控制器功能,但任何规则都没有应用
这是我的代码
if($request->hasFile('propic'))
{
$this->validate($request, [
'name' => 'required', 'alpha','min:2', 'max:255',
'last_name' => 'required', 'alpha','min:5', 'max:255',
'mobile' => 'required', 'string','min:10','max:14', 'regex:/+(9[976]d|8[987530]d|6[987]d|5[90]d|42d|3[875]d|
2[98654321]d|9[8543210]|8[6421]|6[6543210]|5[87654321]|
4[987654310]|3[9643210]|2[70]|7|1)d{1,14}$/',
'email' => 'required', 'string', 'email', 'max:255', 'unique:users,email,'.$setting->id.'',
'propic' => 'required','image','mimes:jpeg,png,jpg,gif,svg','max:2048',
]);
$imageName = time().'.'.$request->propic->extension();
$request->propic->move(public_path('propics'), $imageName);
$setting->propic=$imageName;
$setting->name=$request->input('name');
$setting->last_name=$request->input('last_name');
$setting->mobile=$request->input('mobile');
$setting->email=$request->input('email');
$setting->update();
return Redirect::back()->with('success',__('sentence.User updated successfully'));
}
在撰写本文时,有两种可接受的传递验证规则的格式:
-
作为字符串数组(注意方括号,这是您当前缺少的(:
$this->validate($request, [ 'name' => ['required', 'alpha','min:2', 'max:255'], ... ]);
-
作为单管分隔字符串:
$this->validate($request, [ 'name' => 'required|alpha|min:2|max:255', ... ]);