Laravel: Executive Route:cache Times logicexception

Source: Internet
Author: User
Tags closure prepare serialization



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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.