Upgrading Laravel 7 to Laravel 9 Upgrading Laravel 7 to Laravel 9

October 10, 2022

laravel londinium

This weekend, I have decided it is time to upgrade my londinium.com website from Laravel 7 to the latest Laravel 9. As PHP is now in version 8.1 and the latest version of Laravel needs a minimum of PHP 8.0, so it is a good time to upgrade the website.

Although i could have used a website service like Laravel Shift, I wanted to do it by hand to see the differences.

First step is to install an empty version of laravel 9 which gives me 2 versions with the following URLs

  • localhost:81
  • localhost:91

I simply copied over the files from the old version to the new repo

  • /app/http/controllers
  • /resources/views
  • /routes
  • /public/css
  • /public/js
  • /public/images

and updated the .env file with the db variables and a few settings.

Error: Target Class Controller Does Not Exist

When i loaded the localhost:91/ i got an error that the "Target Class Controller Does Not Exist" this is explained here

laravel.com/docs/8.x/upgrade and here stackoverflow.com/questions/63807930/error-target-class-controller-does-not-exist-when-using-laravel-8

There are a number of solutions but this worked.

Define namespace in RouteServiceProvider as an old version. 

App\Providers\RouteServiceProvider
public function boot()
    {
        $this->configureRateLimiting();

        $this->routes(function () {
            Route::prefix('api')
                ->middleware('api')
                ->namespace($this->namespace)
                ->namespace('App\Http\Controllers')  <------------ Add this
                ->group(base_path('routes/api.php'));

            Route::middleware('web')
                ->namespace($this->namespace)
                ->namespace('App\Http\Controllers') <------------- Add this
                ->group(base_path('routes/web.php'));
        });
    }

The process was pretty easy and this got the basic site working. In the next blog posts I will explain upgrading the php version and also getting the laravel mix, vite and webpack build process working.

It is a delight to work with Laravel, the latest versions are not very different from each others and I enjoy the stability this framework provides. Big thanks to Taylor Otwell and the team.


If you would like to contact me with this form on londinium.com, ilminster.net or via Twitter @andylondon