Laravel 8 Upgrade Strategy
Recently me and my team has been working on Laravel 8 upgrade from Laravel 7.
To facilitate the upgrade we decided to use Laravel Shift.
After reviewing the initial PR created by Laravel Shift, we decided that it would be too risky to make all the changes done by Laravel Shift at once.
Luckily Laravel Shift also provides a Laravel Workbench if you get the yearly subscription for 99 USD/yr for latest version upgrade. By latest version they mean that as long as Laravel 8 is available, upgrades from Laravel 7 to Laravel 8 would be covered under this subscription. Once Laravel 9 is release, upgrades from Laravel 8 to Laravel 9 will be convered also under this subscription.
Laravel Workbench can be used to run different tasks e.g. Upgrade to Laravel Mix 6, Class Based Routes etc.
So we decided to go with the following approach:
- Upgrade Laravel Mix to 6
This went pretty smoothly.
- Upgrade Routes to Class Based Routes
For resource based controllers we ran into a problem in which test case was still picking up namespace from somewhere and appending it in the start. In Laravel 8 the default namespace defined in RouteServiceProvider.php has been removed so in web.php and api.php you have to use fully qualified class names e.g.
Route::get('/users', [\App\Http\Controllers\UserController::class, 'index']);For resource controller you would expect this to work:Route::resource('/users', \App\Http\Controllers\UserController::class);However when working testcase somehow it tries to get the UserController class from the following path:Route::resource('/users', \App\Http\Controllers\App\Http\Controllers\UserController::class);To fix it, after trying multiple things we changed the definition as following to finally get it to workRoute::resource('/users', '\App\Http\Controllers\UserController');
- Formatting
We upgraded our .php_cs.dist file and ran php-cs-fixer locally first on the whole project using the recommendation by Laravel Shifter. Then ran laravel formatter task of Laravel Shift workbench to finalise changes.
- Final Upgrade including moving to Model Factories, Version Upgrades etc.
When we ran composer install there were a lot of packages not compatible with Laravel 8 and PHP 8. So we had to upgrade their versions that were compatible one by one of replace them. This will vary depending upon the packages you use in your project.
Hopefully this will help as a starting point for your Laravel 8 Upgrades. Please go through the following link to see the official documentation regarding the upgrade.
Comments
Post a Comment