Laravel 9

Laravel 9 New Features

Laravel 9

The first Long Term Support update in a 12-month cycle is supposed to be Laravel 9, which was initially scheduled to arrive by September 2021. However, it was later decided to push it until January 2022. Due to Symfony’s intention to release Symfony v6.0 by November 2021 and Laravel’s system dependencies in various community-driven and Symfony 9 modules, the Laravel team decided to postpone the release of Laravel v9. It will take some time and a lot of testing and monitoring against breaking changes before the full Laravel framework is updated to the most recent Symfony version and released to the public. At last, deferring the release of Laravel 9 till January 2022 will better position the Laravel team to release the ensuing LTS annually. Giving the Laravel team two months following the launches of Symfony Now that you are aware of the rationale behind the changes, let’s examine the new Laravel v9 ahead of its scheduled release on January 22, 2022.

 

Laravel 9 New Features

 

Minimum PHP Requirement:

The most recent versions of PHP 8, PHPUnit 9, and several additional requirements will be required for Laravel 9 in the future. As a framework, Laravel is dependent on a number of open-source Symfony 9 libraries. Laravel’s development team was forced to postpone the release of Laravel v9 since Symfony intended to deliver version 6.0 by November 2021. The need for PHP 8 is due to Laravel 9’s reliance on Symfony’s most recent v6.0 version, which only works with PHP 8. To further understand PHP 8’s improvements and features, from the Just-In-Time compiler (JIT) to function Object() { [native code] } property promotion, you may study what is new in PHP 8 and the unique PHP version benchmarks.

 

Anonymous Stub Migration

When using the well-known migration command, Laravel makes anonymous stub migration the default action:

php artisan make:migration

In order to address the Github issue, the anonymous stub migration capability was initially included in Laravel 8.37. Multiple migrations with the same class name might cause problems when trying to reconstruct the complete database, which is where the problem arises. Collisions in migration class names are eliminated by the stub migration feature.

Here is the sample code snippet of what the new migration file will look like:

Migration

Instead of the standard schema::create() function, this code sample employs schema::table.

New Interface for Query Builder

Type hinting in Laravel 9 is quite dependable for refactoring, inactive analysis, and code completion in their IDEs. This is because QueryBuilder, EloquentBuilder, and EloquentRelation all require a shared interface or inheritance. Engineers may still enjoy the new query builder interface for type hinting, refactoring, and static analysis with Laravel 9.

The necessity for a shared interface or heritage between QueryBuilder, EloquentBuilder, and EloquentRelation might be substantially more challenging for developers who rely on sort insights for static analysis, refactoring, or code completion in their IDE.

Query Builder Interface

This release introduced the new Illuminate\Contracts\Database\QueryBuilder interface, in addition to the Illuminate\Database\Eloquent\Concerns\DecoratesQueryBuilder, trait which implements the interface in place of the __call magic function.

Controller route groups

You can now use the controller method of the Laravel 9 Route class to define the controller that will be used for every route in a route group.

Route Controller Group

Scout’s new database engine

The new Laravel Scout database engine is included with Laravel v9. It gives Eloquent models full-text search capabilities. It employs model observers to keep search indexes in sync with Eloquent records and is suitable for applications that use a small or medium-sized database or have a mild workload. When filtering results from your database, this engine will employ “where-like” clauses.

Simply add the LaravelScoutSearchable trait to a model to utilise it:

Laravel Scout Searchable

Route bindings with forced scope

In a route definition, Laravel 9 can now automatically scope the query to get a nested model by its parent by utilizing conventions to infer the parent’s relationship name. Here’s an example of how to use scope bindings:

Scope bindings

Alternatively, you may tell a whole collection of route declarations to utilize scoped bindings:

Group of route definitions to use scoped bindings

 

New helpers

 

Str

Laravel’s Illuminate\Support\Str facade will now employ PHP 8 string functions, which include new methods such as str contains, str starts with, and str ends with. Append and the snake is two new assistants.

Support Str facade

to_route

To expressively redirect to named routes from your routes and controllers, use the to route method, which creates a redirect HTTP response for a given named route:
to_route

 

Why upgrade to Laravel 9?

 

Flysystem 2.0

Flysystem 2.x has replaced Flysystem 1.x in Laravel 9. Flysystem is the engine that drives all of the record modification techniques offered by the Capacity façade. Due to this, your application may need to make a few adjustments. In any event, we made an effort to make this change as logical as we could.

Symfony Mailer

The switch from SwiftMailer, which won’t be supported after December 2021, to Symfony Mailer is one of Laravel 9.x’s largest changes. However, Laravel made an effort to make this action as uniform as is practical for your apps. In light of this, it would be excellent if you carefully read the list of modifications below to make sure your application is flawlessly consistent.

The lang Directory

The resources/lang directory is currently found inside the root project directory in Laravel 9 apps (lang). Make sure your package is publishing to app()->langPath() rather than a hard-coded location if it is publishing language files to this directory.

The Password Rule

The password rule has been changed to the current password, and it now verifies that the input value provided matches the confirmed user’s current password. The unless and when methods As you may be aware, different classes throughout the framework include when and unless methods. If the first method argument’s boolean value evaluates to true or false, these methods can be used to conditionally carry out an action.

 

Our team completed 25+ projects on Laravel development.

We make startup ideas a reality. Do you want to launch your company idea? Infynno Solutions helps you in bringing your concept to reality and design it. Let’s connect and discuss.