How to Upgrade Laravel Version 10 to 11
This tutorial provides a comprehensive, step-by-step guide on upgrading your existing Laravel 10 application to Laravel 11. Carefully follow each step to ensure a smooth and successful upgrade process. Remember to back up your application before proceeding!
1. Backup Your Application
Before making any changes, it's crucial to create a backup of your entire Laravel application. This includes your database, code files, and any other important assets. This will allow you to easily revert to the previous state if something goes wrong during the upgrade process.
For your database, you can use:
php artisan backup:run
Alternatively, you can use database management tools like phpMyAdmin or dedicated backup utilities.
2. Update Composer Dependencies
The first step is to update your application's Composer dependencies. We'll adjust the `require` and `require-dev` sections of your `composer.json` file to include the new Laravel framework and related packages.
{
"require": {
"php": "^8.2",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^11.0",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.7",
"nesbot/carbon": "^2.69"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
"laravel/pint": "^1.0",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0",
"phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^2.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"platform-check": false
},
"minimum-stability": "stable",
"prefer-stable": true
}
Make sure to adjust the versions to the latest stable releases according to your specific project needs. Don't forget to update your minimum PHP version if necessary.
3. Update Configuration Files
Laravel 11 introduces some changes to the configuration structure. You'll need to publish the default configuration files and merge them with your existing configurations. Pay close attention to any deprecated or renamed configuration options.
php artisan config:publish
Compare the newly published config files (located in the `config` directory) with your existing configuration files and merge any necessary changes. Be particularly careful with `app.php`, `auth.php`, `database.php`, and `session.php`.
4. Update `bootstrap/app.php`
Laravel 11 introduces streamlined bootstrapping. Review and update your `bootstrap/app.php` file to align with the new structure. You will need to adjust the code in this file to reflect changes in how the application is bootstrapped.
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(base_path())
->withProviders()
->withFacades()
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->validateCsrfTokens(
except: ['/stripe/*'],
);
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
5. Update Event Broadcasting Configuration
If you are using event broadcasting, review and update your `config/broadcasting.php` configuration file to reflect any changes in the Laravel 11 broadcasting configuration.
Check for any deprecated options or new features related to broadcasting and adjust your configuration accordingly.
6. Update the Autoloader
After modifying the `composer.json` file, it's essential to update the autoloader. This ensures that Composer recognizes the new package versions and configurations.
composer update
This command will update all your dependencies, including Laravel itself. Be patient, as this process can take some time.
7. Run Database Migrations
If there are any database changes in Laravel 11, you'll need to run your database migrations. This will update your database schema to match the new framework version. Before doing so, ensure you have a database backup.
php artisan migrate
8. Clear Application Cache
After updating your dependencies and running migrations, it's a good practice to clear your application cache. This will ensure that your application is using the latest configuration and code.
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
9. Test Your Application
After completing the upgrade process, thoroughly test your application to ensure that everything is working as expected. Pay close attention to any areas that were affected by the upgrade, such as database interactions, form submissions, and API calls. Run your existing tests and create new ones as needed to verify the functionality of your application.
10. Address Deprecations
During the upgrade process, you may encounter deprecation warnings. These warnings indicate that certain features or methods are no longer supported and will be removed in future versions of Laravel. Address these deprecations by updating your code to use the recommended alternatives. This will help ensure that your application remains compatible with future versions of Laravel.
Congratulations! You have successfully upgraded your Laravel 10 application to Laravel 11. Remember to consult the official Laravel upgrade guide for more detailed information and troubleshooting tips. Good luck!