验证在Laravel 5.1中创建用户

时间:2015-08-17 07:23:04

标签: php laravel laravel-5 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'],
    ]);
}

1 个答案:

答案 0 :(得分:1)

您需要将 ValidatesRequests 特征添加到控制器。这是提供 RegistersUsers 特征使用的 throwValidationException 方法的代码段。