验证在 Laravel 5.1 中创建用户

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 特征。这是提供 throwValidationException 方法的代码片段 RegistersUsers 特征使用。