How to Update Laravel 11 to Laravel 12

If you’re running a Laravel 11 application and excited about the new features in Laravel 12, you’re in the right place! Upgrading Laravel may sound complicated, but with the right steps, it becomes a smooth process. In this guide (Update Laravel 11 to Laravel 12), we’ll walk you through updating Laravel 11 to Laravel 12, ensuring that your application remains stable and secure.
Step 1: Backup Your Project
Before making any updates, it’s essential to back up your entire Laravel project, including:
- Database: Export your database to avoid data loss.
- Files & Codebase: Copy your project files to a safe location or use version control (Git).
This ensures that if anything goes wrong, you can easily restore your project.
Step 2: Update Your Composer Dependencies
Laravel uses Composer to manage dependencies. Start by updating Composer to the latest version by running:
composer self-update
Then, update your composer.json
file to require Laravel 12:
"require": {
"laravel/framework": "^12.0"
}
Now, run the following command to update dependencies:
composer update
This will fetch the latest Laravel 12 package and update other dependencies accordingly.
Step 3: Check for Deprecated Methods and Breaking Changes
Laravel updates often come with some breaking changes. After upgrading, carefully review:
- Laravel’s official upgrade guide for Laravel 12.
- Your application code, especially custom service providers, middleware, and models.
If any functions or methods are deprecated, update them as per Laravel 12 documentation.
Step 4: Update Configuration Files
Laravel updates may introduce new configurations. To ensure your application is properly configured:
- Compare your
config
files with the latest ones in a fresh Laravel 12 installation. - If new configuration keys are introduced, add them to your existing config files.
- Run:
php artisan config:clear
php artisan cache:clear
Step 5: Update Database Migrations and Seeds
If Laravel 12 introduces database structure changes, make sure your migrations are updated:
php artisan migrate
For fresh database seeding, run:
php artisan db:seed
Step 6: Test Your Application
After updating, test everything carefully:
- Run unit and feature tests:
php artisan test
Check routes, authentication, and API endpoints. Monitor logs using:
tail -f storage/logs/laravel.log
If you encounter errors, debug them using Laravel’s error handling tools and update the affected parts of your code.
Step 7: Deploy Your Updated Laravel 12 Application
Once everything is working fine, deploy your updated Laravel 12 application by:
- Pushing changes to your Git repository.
- Updating your server and running
composer update
again. - Restarting queues and clearing caches:
php artisan queue:restart
php artisan view:clear
php artisan route:clear
Upgrading Laravel 11 to Laravel 12 may require some effort, but following these steps will ensure a smooth transition. Always back up your data, test thoroughly, and stay updated with Laravel’s latest documentation.
If you need expert help with Laravel development or maintenance, CodeHunger is a great place to explore professional services. Stay ahead with the latest Laravel advancements and keep your applications running efficiently.