# 一刻升級之路 整理好的文件: https://github.com/laravel/vonage-notification-channel/blob/3.x/UPGRADE.md ## form 5.5 to 9.0 ### Composer update 篇 #### 改composer.json - 將 laravel/framework 改版本 - 其他套件可能視情況也要一起調整 #### PHP Fatal error: Declaration of App\Exceptions\Handler::report(Exception $exception) must be compatible with Illuminate\Foundation\Exceptions\Handler::report(Throwable $e) in ...ru; - 改`Exception` to `Throwable` - https://laravel.com/docs/7.x/upgrade#symfony-5-related-upgrades #### Call to undefined function str_slug() - https://stackoverflow.com/questions/57864711/call-to-undefined-function-str-slug-in-laravel-6-0 - https://laravel.com/docs/6.x/upgrade#helpers ``` COMPOSER_MEMORY_LIMIT=-1 composer require laravel/helpers ``` #### **Class 'Illuminate\Http\Resources\Json\Resource' not found** - **這個影響有點大** :crying_cat_face: - https://laravel.com/docs/7.x/upgrade#symfony-5-related-upgrades - 底下有Resource 的區塊 - 要改 `use Illuminate\Http\Resources\Json\Resource` 變成`use Illuminate\Http\Resources\Json\JsonResource` - 如果有用`resource`這個class name 就要改成`use Illuminate\Http\Resources\Json\JsonResource as Resource; ` ### 跑 phpunit 篇 #### phpunit.xml:Your XML configuration validates against a deprecated schema.(警告) ``` vendor/bin/phpunit --migrate-configuration ``` #### Error: Call to undefined function Tests\Feature\Admin\V1\factory() - https://laravel.com/docs/8.x/upgrade#seeder-factory-namespaces ``` COMPOSER_MEMORY_LIMIT=-1 composer require laravel/legacy-factories --dev // composer.json "autoload": { "psr-4": { "App\\": "app/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" } }, ``` #### 原本寫0 可以通過的test 但到了升級之後那裏嚴謹需要false才會通過 - 目前猜不出來是哪裡的upgrade guide 的紀錄 - 懷疑是這個: https://laravel.com/docs/8.x/upgrade #### ReflectionException: Class Barryvdh\Cors\HandleCors does not exist - laravel 7 以支援Cors,可以直接移除試試看 #### TypeError: Argument 2 passed to Symfony\Component\HttpFoundation\Request::setTrustedProxies() must be of the type int, array given - https://laravel.com/docs/5.6/upgrade#upgrade-5.6.0 - 把headers改成`protected $headers = Request::HEADER_X_FORWARDED_ALL;` ### 其他篇 #### route:cache Unable to prepare route [api/admin/v1/priceitem_groups] for serialization. Another route has already been assigned name - 改一下name - https://laravel.com/docs/7.x/upgrade#unique-route-names #### In RouteFileRegistrar.php line 35:Array to string conversion - 後來發現其實前面name 搞定就可以 https://laravel.com/docs/8.x/configuration#additional-environment-files #### php artisan config:cache - 注意自己的.env 配置, 在7還是8之他會根據你在APP_ENV的設定讀取像是.env.testing 或.env.local, 導致在執行指令後感覺反而沒有apply的感覺 ## upgrade to php8 篇 - TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, function "imagejpeg" not found or invalid function name ## upgrade to 9 ### 調整 trustedproxy.php ``` #8 0.516 In trustedproxy.php line 48: #8 0.516 #8 0.516 Undefined constant Illuminate\Http\Request::HEADER_X_FORWARDED_ALL ``` 解決方法: https://laravel.com/docs/9.x/upgrade#the-assert-deleted-method ### jwt-auth 不支援 laravel-9 https://github.com/tymondesigns/jwt-auth/issues/2141 先暫時改用 `php-open-source-save/jwt-auth` https://github.com/PHP-Open-Source-Saver/jwt-auth ### 同事反映: swagger 問題?! ### phpunit faker 問題 https://stackoverflow.com/questions/66481327/how-to-fix-error-abandoned-fzaninotto-faker-packagist-in-composer-2-0-11-version ###### tags: `_ear`