laravel8からlaravel9にしたので備忘録を残す
laravelのupdate作業が降り掛かってきたので、備忘録として残す。
現環境
- AlmaLinux 8.5
- PHP 8.1.4
-
laravel/framework”: “^8.0”
作業方法
9.x アップグレードガイド Laravel
laravel9のアップグレードガイドをざっと見て、composer.jsonを書き換えていく。
アップグレード実行
自分の環境は、バリバリにfacade/ignitionを使用していたので、まずはこれを更新していく。
今回からは、spatie/laravel-ignitionを使用するようだ。
“facade/ignition”: “^2.3.6”,→“spatie/laravel-ignition”: “^1.3”,
後は、アップグレードガイド通りにupdateしてみる。
“laravel/framework”: “^8.0”,→“laravel/framework”: “^9.19”,
“nunomaduro/collision”: “^5.0”,→“nunomaduro/collision”: “^6.1”,
エラー対応1
league/flysystem-aws-s3-v3のバージョンが古いとのことで、調べると現在は^3.0らしいので、これを変更する。
“league/flysystem-aws-s3-v3”: “~1.0”,→“league/flysystem-aws-s3-v3”: “^3.0”,
エラー対応2
Error
Undefined constant Illuminate\Http\Request::HEADER_X_FORWARDED_ALL
at vendor/fideloper/proxy/config/trustedproxy.php:48
44▕ * - 'HEADER_X_FORWARDED_AWS_ELB' (If you are using AWS Elastic Load Balancer)
45▕ *
46▕ * @link https://symfony.com/doc/current/deployment/proxies.html
47▕ */
➜ 48▕ 'headers' => Illuminate\Http\Request::HEADER_X_FORWARDED_ALL,
49▕
50▕ ];
51▕
+9 vendor frames
10 [internal]:0
Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Fideloper\Proxy\TrustedProxyServiceProvider))
+5 vendor frames
16 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
これを読むと、どうやらミドルウェアのプロキシをうんぬんしろって書いてある。
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small...
If you are upgrading your Laravel 8 project to Laravel 9 by importing your existing application code into a totally new Laravel 9 application skeleton, you may need to update your application’s “trusted proxy” middleware.
上記のURLでも良いし、以下のstackoverflowでの解決方法でも良いので、とりあえず対象のファイルを修正していく。
Error: While updating laravel 8 to 9. Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Nothing to install, update or remove
Generating optimized autoload files
Class App\Helpers\Helper located in C:/wamp64/www/vuexylaravel/app\Helpers\helpers.php ...
(やってることは同じだった)
エラー対応3
laravel8→laravel9に変わったことで、メール送信機能がswiftからsymponyに変わった。
メール機能を使っているのであれば、下記を導入しておくと良い。
composer require symfony/mailgun-mailer symfony/http-client
結果
Laravel Framework 9.19.0 になった。