gpt4 book ai didi

laravel 无法为序列化准备路线...。使用闭包

转载 作者:行者123 更新时间:2023-12-02 03:35:55 24 4
gpt4 key购买 nike

当我清除 Laravel 5.2 项目中的缓存时,我看到以下错误消息:

[逻辑异常] 无法准备用于序列化的路线[面板]。使用闭包。

我认为这与路线有关

Route::get('/article/{slug}', 'Front@slug');

与我的 Controller 中的特定方法关联:

public function slug($slug) {
$article = Article::where('slug',$slug)->first();

$id = $article ->id_article ;

if ( ($article=== null) || (is_null($id)) ) return view('errors/Db');

else return view('detail')->with(array('article'=> $article, 'title'=>'My title - '.$article->title));
}`

简而言之,从主视图中,我传递 $slug,这是文章的短链接,通过 $slug,它在数据库中是唯一的,我识别记录,然后将其内容传递到详细 View 。

当我编写该方法时,我没有遇到任何问题,事实上,它的工作原理就像一个魅力,但在我清理缓存后,我收到了该错误,并且主视图中的链接不显示任何短代码。

我哪里做错了?

最佳答案

I think that it's related with a route

Route::get('/article/{slug}', 'Front@slug');

associated with a particular method in my controller:

不,不是这样的。错误消息来自 route:cache 命令,不确定为什么清除缓存会自动调用此命令。

问题是使用闭包而不是 Controller 的路由,它看起来像这样:

//                       Thats the Closure
// v
Route::get('/some/route', function() {
return 'Hello World';
});

由于闭包无法序列化,因此当您有使用闭包的路由时,您无法缓存路由。

关于laravel 无法为序列化准备路线...。使用闭包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45266254/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com