What’s new in Laravel 9?

What’s new in Laravel 9?

What’s New in Laravel 9?

Laravel 9 was released on February 8, 2022, bringing several new features, improvements, and updates. In this post, we’ll explore what’s new in Laravel 9 and guide you step by step on how to upgrade and use these features effectively.

1. Laravel 9 Release Overview

Laravel 9 was the first long-term support (LTS) release with a 2-year bug fix and 3-year security updates. It introduced major improvements in routing, queries, performance, and developer experience.

2. Key Features in Laravel 9

1. PHP 8.0 Minimum Requirement

Laravel 9 requires PHP 8.0 or later, allowing better performance and new language features like attributes, named arguments, and match expressions.

2. Symfony 6.0 Components

Laravel 9 uses Symfony 6.0, enhancing performance and security.

3. New Query Builder Interface

The new query builder allows better type hinting and autocomplete support in IDEs.

Example:

use Illuminate\Database\Query\Builder; function getUsers(Builder $query) { return $query->where('active', 1)->get(); }

4. Improved Eloquent Accessors & Mutators

Laravel 9 simplifies defining accessors and mutators.

Before Laravel 9:

public function getNameAttribute($value) { return ucfirst($value); }

In Laravel 9:

use Illuminate\Database\Eloquent\Casts\Attribute; protected function name(): Attribute { return Attribute::make( get: fn ($value) => ucfirst($value), set: fn ($value) => strtolower($value), ); }

5. Route List Improvements

Running php artisan route:list is now more readable with colorized output and better organization.

6. Laravel Scout Database Engine

Laravel 9 adds a full-text search engine for Laravel Scout, improving database search performance.

7. Flysystem 3.0 Integration

Improved file storage handling with better efficiency and performance.

8. Implicit Route Bindings with Enums

Laravel 9 allows using Enums in route model binding.

use App\Enums\Status; Route::get('/status/{status}', function (Status $status) { return $status->name; });

3. How to Install Laravel 9

To install a fresh Laravel 9 project, run:

composer create-project laravel/laravel laravel9-app

Or via Laravel Installer:

laravel new laravel9-app

4. How to Upgrade to Laravel 9

If you’re upgrading from Laravel 8 to Laravel 9, follow these steps:

Step 1: Update Dependencies

Update composer.json to use Laravel 9 packages:

"require": { "php": "^8.0", "laravel/framework": "^9.0", "nunomaduro/collision": "^6.1" }

Run:

composer update

Step 2: Update Configuration Files

Check and update config files in /config for any changes.

Step 3: Update Middleware & Routes

Check for deprecations in middleware and routes.

Step 4: Test Your Application

Run:

php artisan test

Fix any issues before deploying.

5. Conclusion

Laravel 9 introduced many exciting features like improved query builder, PHP 8.0 support, and new Eloquent enhancements. Upgrading to Laravel 9 ensures better performance and security. Try it out and let us know your thoughts!

Would you like any modifications or additions? 😊

Souy Soeng

Souy Soeng

Our website teaches and reads PHP, Framework Laravel, and how to download Admin template sample source code free. Thank you for being so supportive!

Github

Post a Comment

CAN FEEDBACK
close