Laravel 9: new features

Laravel has been one of the largest for quite some time. PHP frameworks. It is adaptable, scalable and versatile, making it an almost indispensable system for engineers and companies working with PHP. The 9th version of Laravel is already on its way, bringing with it a whole range of new features and solutions. Laravel is firmly established as one of the leading PHP frameworks for building ambitious, robust, and custom web applications, and it’s no surprise.

Laravel always strives to make the development process smoother and faster, so it constantly offers its users new versions with new features, capabilities, improvements and much more. Laravel has already gone through several major updates. Its features and functionality have evolved so much that it has become the leading PHP system for developing web applications.

Laravel 9 was originally scheduled to be released in September 2021, but was pushed back to January 2022, making it the first release with a long-term support (LTS) plan, where updates will occur once a year (instead of the previous 6 months). Let’s discuss the new features and updates of Laravel 9 that have been announced so far.

What should you expect from Laravel 9?

Laravel 9 is said to be the first long-term support product, updated on a 12-month release cycle. It was originally announced to be released in September 2021. However, it was then decided to postpone the release to January 2022. Laravel has system dependencies on many libraries supported by the community and Symfony 9, and Symfony has scheduled the release of Symfony 6.0 for November 2021, which in turn forced the Laravel team to delay the release of Laravel 9. To update the entire Laravel framework to the latest version Symfony, it will take a lot of time, not to mention testing and monitoring all changes before releasing to the market. Finally, delaying the release of Laravel 9 until January 2022 will allow the Laravel team to release subsequent LTS annually. For this reason, the Laravel team delayed the release 2 months after the release of Symfony. Now that you know the reasons for this delay, let’s get to know the new Laravel 9 before its release on January 22, 2022.

New features of Laravel 9

Minimum PHP Requirements

To install Laravel 9 latest version required PHP 8, PHPUnit 9 and a number of other mandatory requirements that will be precisely defined in the near future. Laravel as a framework depends on several libraries maintained by the community and Symfony 9. Since Symfony plans to release version 6.0 by November 2021, this has forced the Laravel development team to delay the release of Laravel 9. The PHP 8 requirement is due to the fact that Laravel 9 solely depends on the latest release Symfony 6.0, which in turn depends on PHP 8. I advise you to read about PHP hosting and innovations of PHP 8, and also get acquainted with comparing the characteristics of different versions of PHPto understand what the benefits and features of PHP 8 are, from the Just-In-Time (JIT) compiler to the promotion of constructor properties.

Anonymous migration

Laravel will introduce anonymous migrations as default behavior when running the popular migration command:

php artisan make:migration

Anonymous migrations were first introduced in Laravel 8.37 to solve an issue with Github. The problem is that multiple migrations with the same name can cause problems when trying to recreate the database. Anonymous migrations eliminate migration class name collisions.

New Query Builder Interface

In Laravel 9, type hinting has become more robust in terms of refactoring, unused code analysis, and autocompletion when typed into the IDE. This is due to the need to use a common interface and inheritance between QueryBuilder, EloquentBuilder and EloquentRelation. However, in Laravel 9 we will be able to take advantage of the new query builder interface for type hinting, refactoring, and static analysis.

PHP 8 string functions

Since Laravel 9 targets PHP 8, Laravel aims to use the most up-to-date string functions. These functions include the use of str_contains(), str_starts_with() and str_ends_with() within the IlluminateSupportStr class. The listed features and improvements in Laravel 9 are just a brief overview of what awaits us in the future. It will undoubtedly have bugs fixed, new features added and, of course, numerous changes.

Why upgrade from Laravel 8 to 9

Flysystem 2.0

Laravel 9.x has transitioned from Flysystem 1.x to 2.x. Under the hood, Flysystem uses all the file handling methods implemented in the Capacity facade. This may require some changes to your application. In any case, we tried to make this transition as smooth as possible.

Symfony Mailer

One of the biggest changes in Laravel 9.x is the move from SwiftMailerwhich has ceased to be supported since December 2021, to Symfony Mailer. However, Laravel has tried to make this transition as smooth as possible for your applications. Even so, it would still be best if you read the changelog below to make sure your application is fully compliant.

Custom castes and null

In previous versions of Laravel, the set method of custom casts was not called if the cast attribute was set to null. However, this behavior was not consistent with the Laravel documentation. In Laravel 9.x, the set method of the caste class will be called with null in the argument

HTTP client default timeout

The HTTP client now has a default timeout of 30 seconds. In other words, if the server does not respond within 30 seconds, an exception will be thrown. Previously, the HTTP client did not have a default timeout, which caused requests to sometimes hang indefinitely. If you want to set a longer timeout for a specific request, you can do this using the method timeout:

" class="formula inline">response = Http::timeout(120)->get(...);

Catalog lang

In Laravel 9.x applications, the resources/lang directory is now located inside the project root directory (lang). If your package publishes language files to this directory, you need to ensure that the package publishes them to app()->langPath()and not along the hard-coded old path.

Password Rule

The password rule, which checks that the entered value matches the current password of the verified user, has been renamed to current_password.

When/unless methods

As you may already know, many different classes in the framework offer methods when And unless. These methods can be used to conditionally perform an action if the boolean value of the method’s first argument is equal to true or false:

$collection->when(true, function ($collection) {
    $collection->merge([1, 2, 3]);
});

Therefore, in previous versions of Laravel, passing a closure to the when or unless methods assumed that the conditional operation would always be executed, since a fuzzy comparison with the closure object always evaluates to true. This often led to unexpected results because developers expect the result of the closure to be used as a boolean value that determines whether the conditional action will be performed. Therefore, in Laravel 9.x, any closures passed to the when or unless methods will be executed, and the value returned by the closure will be considered the boolean value used by the when and unless methods.

Reviews from influencers about Laravel 9

We asked several prominent community members and Twitter influencers to share their thoughts on Laravel 9, and here’s what they had to say:

Graham Cambell

“Laravel 9 is, for the most part, a release that will allow us to make a number of breaking changes and move to Symfony 6 components, from Swift Mailer to Symfony Mailer, as well as Flysystem 2. Almost all new features appeared in Laravel 8, and during the last New features have been coming out almost every week since last year, and Dries, I, and many other colleagues have been working hard to get Laravel 8 and its supporting packages to work on PHP 8.1, so there’s no need to wait for Laravel 9 to move to PHP 8.1which is very cool.”

Taylor Otwell

“Compared to previous major Laravel releases, I consider Laravel 9 to be more of a minor ‘technical’ release. The commitment to only one major release per year has really pushed us to release a lot of products that we would normally reserve for a major release “.

Jess Archer

“Laravel 9 does not contain as many flagship features as a regular Laravel release, since the development team has moved to an annual release cycle, they are planning new features throughout the year. On the site https://laravel-news.com/laravel-9 There is a fairly detailed list of new features. The only thing it doesn’t mention that I’m personally very happy about is the support for generics in the Collection class, which will help improve static analysis.”

Conclusion

Laravel is a popular PHP framework that is increasingly attracting the attention of developers. Its upcoming major release is the main one after the 12-month release cycle, and now we can judge that new “juicy” features will appear in it. Laravel will likely continue to add new features leading up to the release date, so stay tuned for future updates and reviews.

Material prepared in advance of the launch online course “Framework Laravel”.

Recently, as part of the course, there was an open lesson dedicated to the Laravel Telescope tool. If interesting, look in the recording.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *