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

时间:2019-07-05 13:56:19

标签: 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\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.

4 个答案:

答案 0 :(得分:1)

在我的composer.json中,有php artisan optimize在Laravel 5.6中已弃用。 所以我删除了它,它起作用了。

答案 1 :(得分:1)

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

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

这样每次我对 routes/web.phpconfig/app.php 进行更改时,我都必须运行上面的命令来应用更改,然后一次又一次地缓存它们,这很烦人。

所以我这样做了:

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

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

答案 2 :(得分:0)

您可以使用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

答案 3 :(得分:0)

基本的php artisan route:clear 但是,如果您升级到新版本。您可以删除bootstrap/cache中有关缓存文件夹的所有内容。 然后在下面运行一些命令行

php artisan config:clear

php artisan cache:clear

php artisan key:generate

composer dump-autoload

祝你好运!

相关问题