如何清除服务器上的 Laravel 路由缓存

How to clear Laravel route caching on server

这与本地主机上的路由缓存有关

关于本地主机

我的 route.php 文件中有 2 条路线。两者都工作正常。没问题。正在学习route:clear和route:cache,发现下面有个小问题

如果我在 route.php 文件中评论任何一条路线,然后在命令 运行 下评论

php artisan route:cache

这将使路由保持禁用状态,因为路由列表现在在缓存中。现在,转到 route.php 文件并尝试删除注释路由,然后尝试 运行 启用 url。它仍然会显示 404,因为我需要使用以下命令删除缓存

php artisan route:clear

到目前为止,在 localhost 中一切都明白了。没问题。

在 godaddy 上的共享主机服务器上部署后

问题:如何删除服务器上的路由缓存?

如果您想删除服务器上的路由缓存,请删除此文件:

bootstrap/cache/routes.php

如果您想更新它,只需 运行 php artisan route:cache 并将 bootstrap/cache/routes.php 上传到您的服务器。

如果您从本地计算机通过 GIT 上传文件,那么当您使用 BASH 或something like.You 可以像在本地使用一样使用它。

php artisan cache:clear

php artisan route:cache

应该可以。

对于您的案例,解决方案是:

php artisan cache:clear
php artisan route:cache

生产环境中必须优化路由加载:

如果您正在构建具有许多路由的大型应用程序,您应该确保在部署过程中您是 运行 route:cache Artisan 命令:

php artisan route:cache

此命令将所有路由注册减少到缓存文件中的单个方法调用,从而在注册数百个路由时提高路由注册的性能。

Since this feature uses PHP serialization, you may only cache the routes for applications that exclusively use controller based routes. PHP is not able to serialize Closures.

Laravel 5 清除路由、视图、配置的缓存以及应用程序的所有缓存数据

我想分享我的经验和解决方案。当我使用 gitlab 开发我的 laravel 电子商务网站时。在开发过程中,我突然发现一个问题,我的视图缓存出现错误。我确实尝试了很多刷新和其他操作,但我在视图中看不到更多变化,但最后我确实使用 laravel 命令解决了我的问题所以,让我们看看我添加了几个命令以从视图中清除缓存, 路由, 配置等

重新优化class加载器:

php artisan optimize

清除缓存外观值:

php artisan cache:clear

清除路由缓存:

php artisan route:clear

清除视图缓存:

php artisan view:clear

清除配置缓存:

php artisan config:clear

您可以在 web.php

中定义路线
Route::get('/clear/route', 'ConfigController@clearRoute');

并使 ConfigController.php 像这样

   class ConfigController extends Controller
{
    public function clearRoute()
    {
        \Artisan::call('route:clear');
    }
}

然后转到服务器示例 http://your-domain/clear/route

上的那个路由