gpt4 book ai didi

php - Laravel 路由重定向,无需关闭路由缓存

转载 作者:可可西里 更新时间:2023-10-31 23:02:39 28 4
gpt4 key购买 nike

我的 routes.php 文件中有这段代码可以执行重定向。虽然问题是每当我运行 php artisan route:cache 命令时,它都会给我一个错误 Unable to prepare route [article/{params}] for serialization。使用闭包。

我知道这与路由有关,如果它有一个闭包则不允许它被缓存。但是我该如何解决此重定向?

Route::get('article/{params}', function($params) {
return Redirect::to($params, 301);
});

最佳答案

Laravel 5.5 开始,您可以使用:

Route::redirect('/here', '/there', 301);

参见 documentation重定向路由下。

关于php - Laravel 路由重定向,无需关闭路由缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35613579/

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