laravel Unable to prepare route … for serialization. Uses Closure

前端 未结 8 1816
心在旅途
心在旅途 2020-11-30 04:48

When I clear caches in my Laravel 5.2 project, I see this error message:

[LogicException] Unable to prepare route [panel] for serialization. Uses Closure.

8条回答
  •  醉梦人生
    2020-11-30 05:01

    This is definitely a bug.Laravel offers predefined code in routes/api.php

    Route::middleware('auth:api')->get('/user', function (Request $request) { 
         return $request->user(); 
    });
    

    which is unabled to be processed by:

    php artisan route:cache
    

    This definitely should be fixed by Laravel team.(check the link),

    simply if you want to fix it you should replace routes\api.php code with some thing like :

    Route::middleware('auth:api')->get('/user', 'UserController@AuthRouteAPI');
    

    and in UserController put this method:

     public function AuthRouteAPI(Request $request){
        return $request->user();
     }
    

提交回复
热议问题