Laravel 9 – New features
As you may know, Laravel transitioned to yearly releases with the release of Laravel 8. Previously, significant versions were released every 6 months. This transition is intended to ease the maintenance burden on the community and challenge our development team to ship amazing, powerful new features without introducing breaking changes. Therefore, we have shipped a variety of robust features to Laravel 8 without breaking backward compatibilities, such as parallel testing support, improved Breeze starter kits, HTTP client improvements, and even new Eloquent relationship types such as “has one of many”.
Therefore, this commitment to ship great new features during the current release will likely lead to future “major” releases being primarily used for “maintenance” tasks such as upgrading upstream dependencies, which can be seen in these release notes.
Laravel 9 continues the improvements made in Laravel 8.x by introducing support for Symfony 6.0 components, Symfony Mailer, Flysystem 3.0, improved route:list output, a Laravel Scout database driver, new Eloquent accessor/mutator syntax, implicit route bindings via Enums, and a variety of other bug fixes and usability improvements.
Laravel 9.x requires a minimum PHP version of 8.0.
Previous releases of Laravel utilized the Swift Mailer library to send outgoing emails. However, that library is no longer maintained and has been succeeded by Symfony Mailer.
Laravel 9.x upgrades our upstream Flysystem dependency to Flysystem 3.x. Flysystem powers all of the filesystem interactions offered by the Storage facade.
Improved Eloquent Accessors / Mutators
Laravel 9.x offers a new way to define Eloquent accessors and mutators. In previous releases of Laravel, the only way to define accessors and mutators was by defining prefixed methods on your model
Enum Eloquent Attribute Casting
Eloquent now allows you to cast your attribute values to PHP enums. To accomplish this, you may specify the attribute and enum you wish to cast in your model’s $casts property array
Implicit Route Bindings With Enums
PHP 8.1 introduces support for Enums. Laravel 9.x introduces the ability to type-hint an Enum on your route definition and Laravel will only invoke the route if that route segment is a valid Enum value in the URI. Otherwise, an HTTP 404 response will be returned automatically.
Forced Scoping Of Route Bindings
In previous releases of Laravel, you may wish to scope the second Eloquent model in a route definition such that it must be a child of the previous Eloquent model
When using a custom keyed implicit binding as a nested route parameter, Laravel will automatically scope the query to retrieve the nested model by its parent using conventions to guess the relationship name on the parent. However, this behavior was only previously supported by Laravel when a custom key was used for the child route binding.
However, in Laravel 9.x, you may now instruct Laravel to scope “child” bindings even when a custom key is not provided.
Controller Route Groups
You may now use the controller method to define the common controller for all of the routes within the group.
Full-Text Indexes / Where Clauses
When using MySQL or PostgreSQL, the fullText method may now be added to column definitions to generate full text indexes
Laravel Scout Database Engine
If your application interacts with small to medium-sized databases or has a light workload, you may now use Scout’s “database” engine instead of a dedicated search service such as Algolia or MeiliSerach. The database engine will use “where like” clauses and full-text indexes when filtering results from your existing database to determine the applicable search results for your query.
;Rendering Inline Blade Templates
Sometimes you may need to transform a raw Blade template string into valid HTML. You may accomplish this using the render method provided by the Blade facade.
Checked / Selected Blade Directives
For convenience, you may now use the @checked directive to easily indicate if a given HTML checkbox input is “checked”.
Bootstrap 5 Pagination Views
Laravel now includes pagination views built using Bootstrap 5.
Improved Validation Of Nested Array Data
Sometimes you may need to access the value for a given nested array element when assigning validation rules to the attribute. You may now accomplish this using the Rule::forEach method. The forEach method accepts a closure that will be invoked for each iteration of the array attribute under validation and will receive the attribute’s value and explicit, fully-expanded attribute name.
Laravel Breeze API & Next.js
Improved Ignition Exception Page
Ignition, the open source exception debug page created by Spatie, has been redesigned from the ground up. The new, improved Ignition ships with Laravel 9.x and includes light / dark themes, customizable “open in editor” functionality, and more.
Improved route:list CLI Output
The route:list CLI output has been significantly improved for the Laravel 9.x release, offering a beautiful new experience when exploring your route definitions.
Test Coverage Using Artisan test Command
The Artisan test command has received a new –coverage option that you may use to explore the amount of code coverage your tests are providing to your application:
Soketi Echo Server
Although not exclusive to Laravel 9.x, Laravel has recently assisted with the documentation of Soketi, a Laravel Echo compatible Web Socket server written for Node.js. Soketi provides a great, open source alternative to Pusher and Ably for those applications that prefer to manage their own Web Socket server.
Improved Collections IDE Support
Laravel 9.x adds improved, “generic” style type definitions to the collections component, improving IDE and static analysis support. IDEs such as PHPStorm or static analysis tools such as PHPStan will now better understand Laravel collections natively.
Laravel 9.x introduces two new, convenient helper functions that you may use in your own application.
References: Laravel Website