Thinking about upgrading your Laravel 11 application to Laravel 12? You're in the right place! Laravel 12 brings new features, improvements, and optimizations that can enhance your application. While upgrading may seem challenging, following a structured step-by-step process will make it smooth and hassle-free. In this guide, we’ll walk you through everything you need to ensure a successful upgrade.
Step 1: Backup Your Project
Before upgrading, it's crucial to back up your project files and database to prevent data loss in case anything goes wrong.
Step 2: Check Your PHP Version
Laravel 12 requires PHP 8.2 or higher.
If your PHP version is lower than 8.2, update it before proceeding.
Step 3: Update composer.json
Open the composer.json file and locate this line:
"require": {
"laravel/framework": "^11.0"
}
Change it to:
"require": {
"laravel/framework": "^12.0"
}
Step 4: Update Laravel and Dependencies
Now, run the following command to update Laravel and all dependencies:
composer update
If you face dependency conflicts, try:
composer update --with-dependencies
This process will:
- Upgrade Laravel to 12.x
- Update related dependencies
Step 5: Update Laravel Config Files
Laravel 12 may have changes in configuration files. To check for new config options:
Check Differences in Config Files
Run this command to compare your current files with Laravel 12 defaults:
php artisan config:clear
php artisan cache:clear
If needed, manually update files in config/ by checking the latest Laravel 12 config files from the official Laravel GitHub repository.
Step 6: Run Database Migrations
Run the following command to ensure your database structure is up to date:
php artisan migrate
Step 7: Handle Deprecated Features & Breaking Changes
Laravel 12 removes some old methods. Check your code for any deprecated features by running:
php artisan route:clear
php artisan cache:clear
composer dump-autoload
Step 8: Test the Application
Make sure everything works as expected:
php artisan serve
Visit http://127.0.0.1:8000 and verify your app’s functionality.
If you use PHPUnit or Pest, run:
php artisan test
Fix any errors before moving to production.
Step 9: Deploy Laravel 12 to Production
Once tested, deploy the updated application by:
- Pushing changes to GitHub/GitLab
- Deploying to your server
- Running composer install --no-dev on production
- Clearing cache using below command:
php artisan config:clear
php artisan cache:clear
php artisan optimize
Final Step: Verify the Laravel Version
Run: php artisan --version
You should see below output:
Laravel Framework 12.x.x