What does Laravel 9 have to offer?
No sooner has the year started than there is a new release: the great new version of Laravel. As developers, we always look forward to such major updates, as they come with many benefits. Of course these include new tools for writing code, but let’s not forget about security updates, either. Laravel 9.0 provides security updates until February 2024. So to ensure peace of mind, you should install the update now!
Furthermore, technical requirements have been tightened. For example, from this version onwards, PHP 8 is the minimum requirement. That’s great, especially if you consider this an opportunity to immediately opt for PHP 8.1, which ensures that both your development framework and development environment are completely up to date.
Many changes may be invisible to the end user, but that doesn’t make them any less important. What do these major changes in Laravel 9.0 entail?
New Symfony email module
‘Swift Mailer,’ the module Laravel has always used, is no longer maintained. Therefore, the Laravel team has opted for ‘Symfony Mailer.’ An excellent choice, as Laravel already makes extensive use of other Symfony modules under the hood. As a result, everything is properly interconnected. Developers might have to make a small adjustment; users won’t notice anything at all.
Improved accessors / mutators
In Laravel, it has long been possible to adjust data before it enters the database and right after it leaves the database in one place. That means those who want to transform data can do so in a single place, after which it is automatically used throughout your application. It’s incredibly useful! In Laravel 9.0, it’s easier to write this code. For example, you have to write fewer lines of code — and it’s a lot more legible.
Enum support
This feature is only available if you also use PHP 8.1. It’s very useful, too, and it can prevent bugs. An enum is a way to standardize data values in your application. Suppose the database contains an active user marked with the number “1.” That means “1” stands for “active.” If you then have to use the number “1” in your code, it won’t be very legible. It will be meaningless.
In this case, it’s better to use an enum. Simply put, that means you should use “Status::ACTIVE” in your code, which is much clearer to those who read or write the code. You can instantly see what it means. The “1” no longer matters and is only used for the database. Now, it’s possible to record in Laravel that a certain attribute of an entity is an enum. For example, the “status” attribute of a user entity should be a “status” enum. And Laravel will take care of the rest.
You can also enforce that a value in the URL should be an enum. If, for instance, the URL is “/set-user/status/{status},” you can set things up in such a way that this value — “{status}” — must be a valid status that occurs in the enum. Otherwise, you’ll be redirected to a “404 – Not found” page.
Test coverage
It is now easier than ever to see how much test coverage your application has. That way, you can check if all your code is tested. By performing ‘artisan test coverage,’ you’ll see the percentage of code that is tested per folder.
It’s also possible to specify a minimum percentage. This allows you, for example, to easily enforce that your application always requires a minimum amount of testing, have it tested automatically during a code review, and then give feedback to the developer who delivers code.
Many other new features have been added to improve a developer’s life. For a complete overview, you can of course refer to the official Laravel documentation: https://laravel.com/docs/9.x/releases.