在Laravel 5.3中调用未定义的方法Illuminate \ Http \ JsonResponse :: validate()

时间:2016-11-13 04:18:11

标签: laravel-5 jwt laravel-5.3

我正在使用JSON post request和laravel 5.3实现一个注册表单,其中包含以下Controller设置

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\RegistersUsers;


class RegisterController extends Controller
{

use RegistersUsers;

public function __construct()
{
    $this->middleware('guest');
}

protected function validator(array $data)
{
    $data = $data['Register'];
    $validator = Validator::make($data, [
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|min:6|confirmed',
    ]);

    if($validator->fails())
    {
        $errors = $validator->errors()->all()[0];
        //dd($errors);

        return response()->json(['errors'=>$errors]);
    }
    else
    {
        return $validator;
    }
}
protected function create(array $data)
{

    $data = $data['Register'];
    //dd($data);
    User::create([
        //'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
    ]);

    return response()->json(['success' => $data['email']], 200);
}

}

但我希望在使用同一封电子邮件进行多次注册时跟踪服务器错误。我已在客户端处理此问题,但也需要在后端处理。

问题在于验证器功能在错误

之下一直返回
FatalThrowableError in RegistersUsers.php line 31:
Call to undefined method Illuminate\Http\JsonResponse::validate() 

我已经检查了框架代码,并且有一个验证方法似乎无法识别json响应的任何想法?

0 个答案:

没有答案