[英]Validation create user in Laravel 5.1
我想通過restful Api創建用戶,但是驗證創建用戶時出錯:
BadMethodCallException in Controller.php line 283:
Method [throwValidationException] does not exist.
我的驗證代碼和AuthController.php中的創建用戶是:
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
'phone' => 'required|numeric',
'mobile' => 'required|confirmed|min:11|max:11|numeric',
'address' => 'required|min:6',
'state' => 'required',
'city' => 'required',
'post_code' => 'required|numeric|min:10|max:10'
]);
}
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'phone' => $data['phone'],
'mobile' => $data['mobile'],
'address' => $data['address'],
'state' => $data['state'],
'city' => $data['city'],
'post_code' => $data['post_code'],
]);
}
您需要將ValidatesRequests特性添加到控制器。 這是提供RegistersUsers特性使用的throwValidationException方法的代碼段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.