Laravel 5 Laravel如何禁用/删除路由缓存

Laravel 5 Laravel如何禁用/删除路由缓存,laravel-5,Laravel 5,我正忙着将Laravel 5.4升级到5.8,并收到错误消息,无法为序列化准备路由xxx。使用s闭包 我的web.php中有很多闭包,不打算重构它 是否可能以及如何删除/禁用路由缓存 错误: LogicException : Unable to prepare route [login] for serialization. Uses Closure. at C:\App\lv-5-8\vendor\laravel\framework\src\Illuminate\Routing\

我正忙着将Laravel 5.4升级到5.8,并收到错误消息,无法为序列化准备路由xxx。使用s闭包

我的
web.php
中有很多闭包,不打算重构它

是否可能以及如何删除/禁用路由缓存

错误:

   LogicException  : Unable to prepare route [login] for serialization. Uses Closure.

  at C:\App\lv-5-8\vendor\laravel\framework\src\Illuminate\Routing\Route.php:917
    913|      */
    914|     public function prepareForSerialization()
    915|     {
    916|         if ($this->action['uses'] instanceof Closure) {
  > 917|             throw new LogicException("Unable to prepare route [{$this->uri}] for seriali
zation. Uses Closure.");
    918|         }
    919|
    920|         $this->compileRoute();
    921|

  Exception trace:

  1   Illuminate\Routing\Route::prepareForSerialization()
      C:\App\lv-5-8\vendor\laravel\framework\src\Illuminate\Foundation\Console\RouteCacheCommand.
php:62

  2   Illuminate\Foundation\Console\RouteCacheCommand::handle()
      C:\App\lv-5-8\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

  Please use the argument -v to see more details.

您可以使用
php artisan route:clear
命令清除路由缓存:)

来自route:clear命令的帮助文档

Description:
  Remove the route cache file

Usage:
  route:clear

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

php artisan的基本路线:清除 但是如果你升级到新版本。您可以在
引导/cache
中删除关于缓存文件夹的任何内容。 然后运行下面的一些命令行

php artisan配置:清除

php artisan缓存:清除

php artisan密钥:生成

composer转储自动加载


祝你好运

在我的
composer.json
中,有一个
php artisan optimize
在Laravel 5.6中被弃用。
所以我删除了它,它可以正常工作。

您正在缓存配置和路由。 就像我以前做的那样,通过运行多个命令

php artisan config:cache
php artisan config:clear
php artisan route:cache
php artisan route:clear
php artisan optimize
这样,每次我在
routes/web.php
config/app.php
中进行更改时,我都必须运行上述命令来应用更改,然后一次又一次地缓存它们,这很烦人

因此,我通过这样做修复了它:

@REM php artisan config:cache
php artisan config:clear
@REM php artisan route:cache
php artisan route:clear
@REM php artisan optimize

现在,我在配置和路由中所做的每一项更改都会立即生效,而无需重置缓存。

通常路由缓存文件位于bootstrap/cache/routes.php。您可以尝试删除它,看看它是否解决了问题。仍然会收到错误逻辑异常:无法为序列化准备路由[xxx/xxx]。使用Closur e。在运行route:cache时是否会显示此错误?或者路线:清楚吗?。我问这个问题是因为route:cache不允许缓存,如果route文件至少有一个route的方法作为closure.php artisan route:cache。我知道,唯一可行的方法是将web.php中的所有closure重构为它自己的控制器类。然后route:cache命令将不再显示错误。您应该能够通过注释关闭路由来尝试此操作,然后运行route:cache。@Bas请将您的所有错误发布到Communication上。我们有很多英雄可以帮助解决这个问题。