Upgrading a Laravel project from version 5.8 to Laravel 12

Share:

Upgrading your Laravel project from version 5.8 to Laravel 12 is a major upgrade that requires careful planning. Since Laravel 12 is significantly different from Laravel 5.8, you need to follow these steps systematically:

Step 1: Review Laravel Upgrade Guides

Laravel follows semantic versioning, so you need to upgrade step by step:
5.8 → 6.x → 7.x → 8.x → 9.x → 10.x → 11.x → 12.x
Each major version may introduce breaking changes, so check the Laravel Upgrade Guide.


Step 2: Backup Your Project

Before making any changes:

  • Backup your database
  • Backup your project files
  • Store a copy in a safe location in case you need to rollback.

Step 3: Upgrade PHP Version

Each Laravel version has specific PHP requirements:

  • Laravel 6.x to 9.x → PHP 7.3 – 8.0
  • Laravel 10 → PHP 8.1
  • Laravel 11+ → PHP 8.2
  • Laravel 12 → PHP 8.2+ (Recommended)

Make sure your server has PHP 8.2 installed before upgrading Laravel.


Step 4: Update Dependencies

Upgrade dependencies in steps, modifying composer.json and running composer update for each version.

Upgrade to Laravel 6.x (LTS)

  1. Update composer.json:jsonCopyEdit"laravel/framework": "^6.0"
  2. Run:bashCopyEditcomposer update
  3. Follow the Laravel 6.x upgrade guide for breaking changes.

Repeat this process for each Laravel version step by step:

bashCopyEditcomposer require laravel/framework:^7.0
composer update

… and so on, until you reach Laravel 12.


Step 5: Update Core Laravel Files

After each upgrade step, run:

bashCopyEditphp artisan migrate
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear

Manually review and update:

  • config/app.php
  • bootstrap/app.php
  • New files in config/
  • Middleware, routes, and controllers (as Laravel changed its structure over versions)

Step 6: Update Authentication System

  • Laravel 5.8 uses auth.php with controllers.
  • Laravel 8+ uses Laravel Breeze, Jetstream, or Fortify.
  • If you’re using the default auth system, you may need to install:bashCopyEditcomposer require laravel/ui php artisan ui bootstrap --auth

Step 7: Update Dependencies and Packages

Many third-party packages used in Laravel 5.8 may not support Laravel 12.
Run:

bashCopyEditcomposer outdated
  • Check the latest compatible versions.
  • Update package dependencies.

If any package is no longer maintained, find alternatives.


Step 8: Update Blade and Routing System

  • Laravel 8 introduced Route Caching and Route Caching Improvements.
  • Laravel 9+ prefers implicit model binding.

If you’re using:

phpCopyEditRoute::get('users/{id}', 'UserController@show');

Change it to:

phpCopyEditRoute::get('users/{user}', [UserController::class, 'show']);

Step 9: Fix Deprecated Functions

Run:

bashCopyEditphp artisan deprecations

Laravel will list any deprecated functions you need to replace.


Step 10: Test Everything

  • Run unit tests:bashCopyEditphp artisan test
  • Check logs for errors:bashCopyEdittail -f storage/logs/laravel.log
  • Ensure all pages and API endpoints work correctly.

Step 11: Deploy and Monitor

Once you’re confident everything works:

  1. Push to Staging → Test thoroughly.
  2. Deploy to Production → Ensure all dependencies, routes, and services work.

Alternative: Fresh Installation & Code Migration

If the upgrade path becomes too complex, another approach is:

  1. Install a fresh Laravel 12:bashCopyEditcomposer create-project laravel/laravel my_project
  2. Move your app/ logic, routes, and database migrations manually.
  3. Rewrite old authentication & services using Laravel 12 standards.

LET’S KEEP IN TOUCH!

We’d love to keep you updated with our latest news and offers 😎

We don’t spam! Read our privacy policy for more info.