Laravel学习二:执行route:cache时报LogicException

WBOY
Release: 2016-06-23 13:32:27
Original
1171 people have browsed it

laravel5的路由支持缓存。需要执行以下命令:

php artisan route:cache
Copy after login

执行完毕后,报出以下错误:

Route cache cleared![LogicException]Unable to prepare route [/] for serialization. Uses Closure.
Copy after login

这个异常的错误信息,提示的已经非常明确了:大概意思就是说在闭包里边,是不能够进行路由缓存的。那么现在就有两种办法:
① 想要继续使用闭包,那就只能放弃路由缓存(至少目前我没有其他办法,如果你有,记得告诉我)。
② 那就是在路由里边,也就是route.php中,不要使用闭包的方式,统统改为控制器。

具体例子:

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

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

Route cache cleared!Routes cached successfully!
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template