Update cookies preferences

Upgrade Laravel 9 to Laravel 10

Popular PHP framework Laravel has another release. It is worth keeping your apps and projects up to date to prevent security and performance issues.

Laravel is a popular open-source PHP web application framework used for developing robust and scalable web applications. With the release of Laravel 10, many developers are now looking to upgrade their Laravel 9 projects to the latest version. 

This article will guide you through the process of upgrading your Laravel 9 project to Laravel 10.

Before you start your upgrade

Before starting the process, it is essential to ensure that your current Laravel 9 project is up to date. You should have the latest version of Laravel 9 installed, and all dependencies should be up to date. You can check the current version of Laravel installed in your project by running the following command:

php artisan --version

Once you have confirmed that your Laravel 9 project is up to date, you can proceed with the upgrade process.

Upgrade Laravel Dependencies

The first step is to update the dependencies of your Laravel project to their latest version. 

You can do this by updating the composer.json file of your project. Open the file and update the version of Laravel to ^10.0 along with other dependencies:

laravel/framework to ^10.0

laravel/sanctum to ^3.2

doctrine/dbal to ^3.0

spatie/laravel-ignition to ^2.0

Then run the following command:

composer update

This command will update all the dependencies of your project, including Laravel, to their latest version.

Update Configuration Files

The next step is to update the configuration files of your Laravel project. Laravel 10 introduced some changes to the configuration files, and you need to update them accordingly. Here are the changes you need to make:

1. In the config/app.php file, change the value of the "timezone" key to your timezone.
2. In the config/auth.php file, change the value of the "guards" key to the following:

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],
    'api' => [
        'driver' => 'token',
        'provider' => 'users',
        'hash' => false,
    ],
],

3. In the config/session.php file, change the value of the "same_site" key to "lax".

4. In the app/Http/Kernel.php file, remove line containing

\Fruitcake\Cors\HandleCors::class,

Update Blade Syntax

Laravel 10 introduced some changes to the Blade syntax. You need to update your Blade templates accordingly. Here are the changes you need to make:

1. The "@method" directive is no longer supported in Blade templates. You should use the "@csrf" directive instead.

2. The "@error" directive has been replaced with the "@if($errors->any())" directive.

Update Route Definitions

Laravel 10 introduced some changes to route definitions. You need to update your route definitions accordingly. Here are the changes you need to make:

1. The "Route::fallback" method has been replaced with the "Route::any('{any}', …" method.

2. The "Route::get" method now accepts a second parameter, which is an array of middleware.

3. The "Route::middleware" method has been deprecated. You should use the "Route::aliasMiddleware" method instead.

Update Models

Laravel 10 introduced some changes to models. You need to update your models accordingly. Here are the changes you need to make:

1. The "HasFactory" trait has been replaced with the "HasFactoryTrait" trait.

2. The "scope" method has been replaced with the "apply" method.

Update Controllers

Laravel 10 introduced some changes to controllers. You need to update your controllers accordingly. Here are the changes you need to make:

1. The "validation" method has been replaced with the "validate" method.

2. The "authorize" method has been replaced with the "authorizeForUser" method.

Update Migrations

Laravel 10 introduced some changes to migrations. You need to update your migrations accordingly. Here are the changes you need to make:

1. The "bigInteger" method has been replaced with the "bigIntegerUnsigned" method.

2. The "unsignedBigInteger" method has been deprecated. You should use the "bigIntegerUnsigned" method instead.

Update Tests

Laravel 10 introduced some changes to tests. You need to update your tests accordingly. Here are the changes you need to make:

1. The "TestCase" class has been replaced with the "Tests\TestCase" class.

2. The "DatabaseTransactions" trait has been replaced with the "RefreshDatabase" trait.

Run Migration and Test

Once you have updated your Laravel 9 project to Laravel 10, you need to run the migration to update your database schema. To do this, run the following command:

php artisan migrate

You should also run your tests to ensure that everything is working as expected. To do this, run the following command:

php artisan test

Conclusion

Upgrading your Laravel 9 project to Laravel 10 is a straightforward process. You need to update your dependencies, configuration files, Blade syntax, route definitions, models, controllers, migrations, and tests. Once you have made all the necessary changes, you can run the migration and test to ensure that everything is working as expected. 

With the latest version of Laravel, you can take advantage of new features and enhancements that will improve the performance and scalability of your web application.

Looking to optimise your website? Check out the Laravel services we have to offer!


Sebastian

Sebastian Tracz

Senior Magento Developer

Sebastian is a Senior Magento Developer who has worked on eCommerce projects since 2019 and has been with Develo since 2021. Seb’s favourite aspect of web development is impacting clients’ businesses through meticulous detail in development. His favourite aspects of Magento are its flexibility for client growth and its supportive community. His best achievement from his time at Develo so far is writing a top-performing Laravel blog. Outside of work, he is a rockstar in several bands..

Develo is a leading Magento agency and eCommerce web development company based in Birmingham, in the UK, serving clients globally since 2010. We provide our Learn articles to share knowledge of magento web development, web app development and more to the wider web developer community. To extend your team with our white label web developers, collaborate or consult with us on your project contact us here.


...
Sebastian

share:

Ready to start your next project?

See how we can help you accelerate your business