Laravel更新到5.8,更新了依赖项

时间:2019-03-05 23:31:38

标签: php laravel laravel-5 updates

我目前将laravel从5.2更新到5.8。在整个过程中,我可以正常工作并显示该站点,但是我没有添加所有5.8依赖项,就好像在5.8上从头开始项目一样。因此,我从头开始创建了一个laravel项目,以查看其中包含了什么,然后我开始慢慢移动内容。目前,我正在尝试使composer.json与新的laravel 5.8项目几乎相同。这是有效的-

{
  "name": "laravel/laravel",
  "description": "The Laravel Framework.",
  "keywords": [ "framework", "laravel" ],
  "license": "MIT",
  "type": "project",
  "require": {
    "php": "^7.1.3",
    "laravel/framework": "5.8.*",
    "intervention/image": "^2.3",
    "guzzlehttp/guzzle": "^6.2",
    "fideloper/proxy": "^4.0",
    "laravel/cashier": "~7.0",
    "codedge/laravel-fpdf": "^1.0",
    "phpseclib/phpseclib": "1.0.*",
    "laravelcollective/html": "~5.0",
    "maatwebsite/excel": "^2.1",
    "phpoffice/phpspreadsheet": "^1.4"
  },
  "require-dev": {
    "fzaninotto/faker": "~1.4",
    "filp/whoops": "~2.0",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "^7.5",
    "symfony/css-selector": "^4.0",
    "symfony/dom-crawler": "^4.0"
  },
  "autoload": {
    "classmap": [
      "database"
    ],
    "psr-4": {
      "App\\": "app/"
    }
  },
  "autoload-dev": {
    "classmap": [
      "tests/TestCase.php"
    ]
  },
  "scripts": {
    "post-root-package-install": [
      "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
      "php artisan key:generate"
    ],
    "post-install-cmd": [
      "Illuminate\\Foundation\\ComposerScripts::postInstall",
      "php artisan optimize"
    ],
    "post-update-cmd": [
      "Illuminate\\Foundation\\ComposerScripts::postUpdate",
      "php artisan optimize"
    ],
    "post-autoload-dump": [
      "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
      "@php artisan package:discover"
    ]
  },
  "config": {
    "preferred-install": "dist"
  }
}

我已更改为-

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": "^7.1.3",
        "laravel/framework": "5.8.*",
        "intervention/image": "^2.3",
        "guzzlehttp/guzzle": "^6.2",
        "fideloper/proxy": "^4.0",
        "laravel/cashier": "~7.0",
        "codedge/laravel-fpdf": "^1.0",
        "phpseclib/phpseclib": "1.0.*",
        "laravelcollective/html": "~5.0",
        "maatwebsite/excel": "^2.1",
        "phpoffice/phpspreadsheet": "^1.4",
        "laravel/tinker": "^1.0"
    },
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "fzaninotto/faker": "^1.4",
        "filp/whoops": "^2.0",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.5",
        "symfony/css-selector": "^4.0",
        "symfony/dom-crawler": "^4.0"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-root-package-install": [
            "php -r \"copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    }
}

在尝试运行此更新脚本后,尽管出现类似如下的错误。

Package manifest generated successfully.
> post-update-cmd: Illuminate\Foundation\ComposerScripts::postUpdate
> post-update-cmd: php artisan optimize
Configuration cache cleared!
Configuration cached successfully!
Route cache cleared!

   LogicException  : Unable to prepare route [api/user] for serialization. Uses Closure.

  at C:\Base\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 serialization. Uses Closure.");
    918|         }
    919|
    920|         $this->compileRoute();
    921|

  Exception trace:

  1   Illuminate\Routing\Route::prepareForSerialization()
      C:\Base\vendor\laravel\framework\src\Illuminate\Foundation\Console\RouteCacheCommand.php:62

  2   Illuminate\Foundation\Console\RouteCacheCommand::handle()
      C:\Base\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

  Please use the argument -v to see more details.
Script php artisan optimize handling the post-update-cmd event returned with error code 1

任何建议

1 个答案:

答案 0 :(得分:1)

我知道了,默认情况下api使用的路由中包含function()。由于闭包无法序列化,因此当您有使用闭包的路由时,就无法缓存路由。

FIX ---

//Route::middleware('auth:api')->get('/user', function (Request $request) {
//    return $request->user();
//});

在\ routes \ api.php中注释了测试路由