How to Upgrade from Laravel6 to Laravel8
Thank you for your continued support.
This article contains advertisements that help fund our operations.
⇨ Click here for the table of contents for Laravel articles
I tried upgrading from Laravel6 to Laravel8. I edited Laravel8 in composer.json and ran composer update. I feel like it's going well, but I want to see what version dependency errors come up.
Here is the package status of Laravel6 before the change.
"require": {
"php": "^7.2.5|^8.0",
"diglactic/laravel-breadcrumbs": "^6.1",
"fideloper/proxy": "^4.4",
"laravel/framework": "^6.20",
"laravel/tinker": "^2.5",
"league/flysystem-aws-s3-v3": "~1.0",
"weidner/goutte": "^1.6"
},
"require-dev": {
"facade/ignition": "^1.16.4",
"fakerphp/faker": "^1.9.1",
"laravel/ui": "^1.0",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "^8.5.8|^9.3.3"
},
Conclusion (After modification)
composer.json
"require": {
"php": "^7.2.5|^8.0",
"diglactic/laravel-breadcrumbs": "^6.1",
"fideloper/proxy": "^4.4",
"laravel/framework": "^8.0",
"laravel/tinker": "^2.5",
"league/flysystem-aws-s3-v3": "~1.0",
"weidner/goutte": "^1.6"
},
"require-dev": {
"facade/ignition": "^2.3.6",
"fakerphp/faker": "^1.9.1",
"laravel/ui": "^3.0",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^8.5.8|^9.3.3"
},
Further modifications are required after this.
Modify app/Exceptions/Handler.php
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
// Content remains the same from Laravel 6 to Laravel 8
}
Upgrade Steps
Change the Laravel version specification in composer.json
"laravel/framework": "^8.0",
Command
composer update
Version error occurs
Problem 1
- Conclusion: don't install laravel/framework v8.0.0 (conflict analysis result)
~~~~~~~~~~~~~~~
- laravel/ui[v1.0.0, ..., 1.x-dev] require illuminate/support ~5.8|^6.0 -> satisfiable by illuminate/support[v5.8.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev].
- Only one of these can be installed: illuminate/support[v5.0.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev], laravel/framework[v8.0.0, ..., 8.x-dev]. laravel/framework replaces illuminate/support and thus cannot coexist with it.
- Root composer.json requires laravel/framework ^8.0 -> satisfiable by laravel/framework[v8.0.0, ..., 8.x-dev].
- Root composer.json requires laravel/ui ^1.0 -> satisfiable by laravel/ui[v1.0.0, ..., 1.x-dev].
Modify laravel/ui to version 3
Edit composer.json
"laravel/ui": "^3.0",
Command
composer update
Version error with symfony
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires facade/ignition ^1.16.4 -> satisfiable by facade/ignition[1.16.4, ..., v1.x-dev].
- You can only install one version of a package, so only one of these can be installed: symfony/console[v2.3.10, ..., 2.8.x-dev, v3.0.0-BETA1, ..., 3.4.x-dev, v4.0.0-BETA1, ..., 4.4.x-dev, v5.0.0-BETA1, ..., 5.4.x-dev, 6.0.x-dev].
- Conclusion: install symfony/console v5.1.0 (conflict analysis result)
Change as follows
"require-dev": {
"facade/ignition": "^2.3.6",
"nunomaduro/collision": "^5.0",
The upgrade itself went smoothly.
However, errors occurred so I will address them in the next section.
File Modifications
Error Message
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255
After the upgrade, errors occur with php artisan commands like the above.
Modification in app/Exceptions/Handler.php
Errors seem to occur because this file has different contents between Laravel 6 and 8.
Modify the content completely to adhere to Laravel 8 specifications
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
// Content remains the same from Laravel 6 to Laravel 8
}
Apply the changes and run
composer update
php artisan -v
Laravel Framework 8.60.0
Successfully upgraded to Laravel 8!
Related Articles
⇨How to Implement Authentication in Laravel8 with Jetstream
Summary
That's all.
There are probably many similar articles out there, but I hope this was helpful.
If you have any feedback or opinions, please feel free to contact me via Twitter DM!
Thank you and goodbye!
Popular Posts
Deploying PHP7.4 + Laravel6 Project to AWS EC2
Implementing Breadcrumbs in Laravel with laravel-breadcrumbs