The LARAVEL5 route supports caching. You need to execute the following command:
PHP Artisan Route:cache
After execution, report the following error:
Route cache cleared!
[LogicException]
Unable to prepare route [api/user] for serialization. Uses Closure.
This abnormal error message, the hint is already very clear: the approximate meaning is that in the closure of the inside, is not able to do the route cache. Then there are two ways to do it now:
① want to continue using closures, you can only abandon the routing cache (at least for now I have no other way, if you have, remember to tell me).
② that is in the routing inside, that is, route.php , do not use closures, all changed to the controller.
routes/api.php, temporarily comment the following code:
/*Route::middleware(‘auth:api‘)->get(‘/user‘, function (Request $request) {
return $request->user();
});*/
Execute PHP Artisan Route:cache again
Route cache cleared!
[LogicException]
Unable to prepare route [/] for serialization. Uses Closure.
routes/api.php, modify the route to non-closures:
/*Route::get(‘/‘, function () {
return view(‘welcome‘);
});*/
Route::get(‘/‘, ‘[email protected]‘);
New/app/http/controllers/homecontroller.php
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class HomeController extends Controller{
public function Index(){
return view(‘welcome‘);
}
}
It's done right now. Execute php artisan route:cache again, you can see the successful information prompt:
Route cache cleared!
Routes cached successfully!
Reference: http://blog.csdn.net/hel12he/article/details/46550645
Laravel: Executive Route:cache times logicexception