Laravel5学习笔记:执行route:cache时报LogicException - 小众知识


2013年01月27日 14:18:05 苏内容


php artisan route:cache1


Route cache cleared!
Unable to prepare route [/] for serialization. Uses Closure.123

① 想要继续使用闭包,那就只能放弃路由缓存(至少目前我没有其他办法,如果你有,记得告诉我)。 
② 那就是在路由里边,也就是route.php中,不要使用闭包的方式,统统改为控制器。


// 之前,报错的路由Route::get('/', function(){
    return veiw('welcome');
});// 修改之后,能够路由缓存的方式Route::get('/', 'HomeController@index');12345678

现在就搞定啦。再次执行 php artisan route:cache 可以看到成功的信息提示啦:

Route cache cleared!Routes cached successfully!

an into this little issue when trying to use route:cache on Laravel 5.

Route cache cleared!
Unable to prepare route [posts/laravel's-new-forelse-construct] for serialization. Uses Closure.

The exception is pretty clear, but it's worth noting that closure type routes will not be compatible when trying to use the route:cache command. You have a couple of options: forgo cached routing and the speed improvement or move your routes into a controller. I did the latter.

// Previously
Route::get('posts/laravel's-new-forelse-construct', function()
    return Redirect::to('posts/laravels-new-forelse-construct', 301);

// Currently
Route::get('posts/laravel's-new-forelse-construct', 'RedirectsController@getPostsLaravelsNewForelseConstruct');

Now that your routing is handled by a controller instead of a closure you'll be able to cache your routes as you want.

Even with Forge there can still be key differences between a local and online environment. The only two things I can think of right now are:

  1. Your Forge environment may have cached your config files. If so you need to run php artisan config:cache to recache them. Otherwise any changes in your config files - like a new provider in app.php say - wont be picked up when you deploy to your server. I had to ssh in and manually delete the cached file off my server in the past to get a stuck deployment working again

  2. A long shot but double check your camel case name is the same in all references to your interface. GarageWarrantyInterface.php vs interface Garagewarrantyinterface { .. I've had various local and server environments interpret upper case differently



2018-03-12 23:25:27

Really tons of awesome tips! forum cialis generique <a href="">buy cialis online</a> cialis daily pill <a href=>cialis generic</a>


2018-03-14 00:25:36

Seriously many of amazing material. how good is daily cialis <a href="">cialis without a doctor prescription</a> cialis diario 0800 <a href=>buy cialis online</a>


2018-03-14 12:51:28

Useful info. Kudos. what happens after taking cialis <a href="">cialis generic</a> cialis tablete kupovina <a href=>cialis generic</a>