1、创建基于FormRequest的表单验证类
php artisan make:request UserRequest
2、在UserRequest.php类中
public function authorize()
{
return true;
}
public function rules()
{
return [
'name' => 'required|between:3,25|regex:/^[A-Za-z0-9\-\_]+$/|unique:users',
'email' => 'required|email',
'introduction' => 'max:80',
];
}
3、UserController.php中
public function update(User $user, UserRequest $request)
{
$user->update($request->all());
}
网友评论