首页 > 解决方案 > 为什么我总是在新创建时清除路由和缓存路由?

问题描述

我正在使用 Laravel 8,但我遇到了路由问题。当我创建路由时,在运行以下命令后它不会出现在路由列表中

php artisan route:clear
php artisan route:cache

我得到了所有的路线。我该如何解决。为什么我为新路线运行这些命令?

标签: laravel

解决方案


文档

优化路由加载

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

php artisan route:cache

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

您应该只php artisan route:cache在部署期间运行,而在本地开发时,您不应该缓存您的路线,否则您创建的新路线在您运行php artisan route:clearphp artisan route:cache再次运行之前不会被注册。

php artisan route:cache
// clears the route cache and then re caches the routes

php artisan route:clear
// clears the route cache

推荐阅读