public function store(Request $request) { $this->validate($request, [ 'name' => 'required|max:50', 'email' => 'required|email|unique:users|max:255', 'password' => 'required|confirmed|min:6' ]); return; }
验证规则:
1.存在性验证
'name' => 'required'
2.长度验证
'name' => 'min:3|max:50'
3.格式验证
'email' => 'email'
4.唯一性验证
'email' => 'unique:users'
'unique:users'是针对数据表users的唯一性验证。
5.密码匹配验证
'password' => 'confirmed'
(如果密码的表单字段名为'password',则要求确认密码字段名为'password_confirmation')