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

时间:2017-01-21 08:48:25

标签: authentication jwt laravel-5.3 registration postman

我正在使用Laravel 5.3

的邮递员实施注册表并发送帖子请求

它适用于网络但我在邮递员中看到以下例外

FatalErrorException in RegistersUsers.php line 31:
Call to undefined method Illuminate\Http\JsonResponse::validate()

Auth\RegisterController

中的验证方法
   protected function validator(array $data)
    {
        if(Request::wantsJson()) {
            $rules  =   array(
            'first_name'    =>  'required',
            'last_name'     =>  'required',
            'email'         =>  'required',
            'password'      =>  'required',
            'phone_number'  =>  'required',

            );
            $validator  =   Validator::make($data, $rules);
            if($validator->fails()) {
                return response()->json($validator->messages());

            }
        } else {
            return Validator::make($data, [
                'name' => 'required|max:255',
                'email' => 'required|email|max:255|unique:users',
                'password' => 'required|min:6|confirmed',
            ]);

        }

    }

错误的完整堆栈跟踪

FatalErrorException in RegistersUsers.php line 31:
Call to undefined method Illuminate\Http\JsonResponse::validate()
in RegistersUsers.php line 31
at FatalErrorException->__construct() in HandleExceptions.php line 133
at HandleExceptions->fatalExceptionFromError() in HandleExceptions.php line 118
at HandleExceptions->handleShutdown() in HandleExceptions.php line 0
at RegisterController->register() in Controller.php line 55
at call_user_func_array:{/var/www/iproximity-web/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:55}() in Controller.php line 55
at Controller->callAction() in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch() in Route.php line 190
at Route->runController() in Route.php line 144
at Route->run() in Router.php line 653
at Router->Illuminate\Routing\{closure}() in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}() in RedirectIfAuthenticated.php line 24
at RedirectIfAuthenticated->handle() in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}() in SubstituteBindings.php line 41
at SubstituteBindings->handle() in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}() in ThrottleRequests.php line 49
at ThrottleRequests->handle() in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}() in Pipeline.php line 104
at Pipeline->then() in Router.php line 655
at Router->runRouteWithinStack() in Router.php line 629
at Router->dispatchToRoute() in Router.php line 607
at Router->dispatch() in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}() in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}() in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle() in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}() in Pipeline.php line 104
at Pipeline->then() in Kernel.php line 150
at Kernel->sendRequestThroughRouter() in Kernel.php line 117
at Kernel->handle() in index.php line 54
at {main}() in index.php line 0

1 个答案:

答案 0 :(得分:0)

验证器方法应该返回Validator实例。在Request :: wantsJson()的情况下,你返回一个JsonResponse(失败时)或什么都没有(成功时)。您可能应该返回$ validator。