[英]Laravel update to 5.8, updating dependencies
I currently have laravel updated to 5.8 from 5.2.我目前已将 laravel 从 5.2 更新到 5.8。 Through the process I have it working and displaying the site, but I don't have all of the 5.8 dependencies added in that would be there as if I started the project from scratch on 5.8.
在整个过程中,我让它工作并显示站点,但我没有添加所有 5.8 依赖项,就像我在 5.8 上从头开始项目一样。 So I created a laravel project from scratch to see what would be included and I started moving things over slowly.
所以我从头开始创建了一个 laravel 项目,看看会包含什么,然后我开始慢慢地移动。 Currently I am trying to get the composer.json almost identical to a new laravel 5.8 project.
目前我试图让 composer.json 与新的 laravel 5.8 项目几乎相同。 This is what was working --
这就是工作 -
{
"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"
}
}
Which I've changed to --我已经改成——
{
"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"
]
}
}
After trying to run this update script though I get an error that looks like this.在尝试运行此更新脚本后,虽然我收到了如下所示的错误。
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
Any Suggestions有什么建议
I figured it out, the api by default uses a route that has a function() in it.我想通了,默认情况下,api 使用一个包含 function() 的路由。 Since Closures can not be serialized, you can not cache your routes when you have routes which use closures.
因为闭包不能被序列化,所以当你有使用闭包的路由时你不能缓存你的路由。
FIX ---使固定 - -
//Route::middleware('auth:api')->get('/user', function (Request $request) {
// return $request->user();
//});
Commented out the test Route in \\routes\\api.php注释掉\\routes\\api.php 中的测试路由
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.