Notable new features of Laravel 9

Tram Ho

Laravel 9 continues the improvements made in Laravel 8.x by introducing support for Symfony 6.0, Symfony Mailer, Flysystem 3.0 components, improved route:list output, Laravel Scout database driver , Eloquent accessor / mutator syntax, binding via Enums and many other types of bug fixes and improvements.

PHP Version

Laravel 9 requires PHP version 8.0 – 8.1 and Symfony 6.0

Controller route groups

You can use the controller method of Laravel 9 Route class

Better accessors and mutators in Eloquent

In Laravel 9, you can use Illuminate Database Eloquent Casts Attribute to declare a prefix. Using a method call, you can now both get and set properties.

Fulltext indexes and where clauses

If you are using MySQL or PostgreSQL in your Laravel application, you can now use the fulltext method on the column definition in your migration to create a full-text index.

You can then use the whereFullText and orWhereFullText to add to your query.

The new Scout database engine

Laravel v9 comes out with the new Laravel Scout database engine. It provides full-text search for Eloquent models. This tool will use “where-like” clauses when filtering results from your database. To use you just add to your model : LaravelScoutSearchable

Breeze API with Next.js

Laravel v9 includes a Next.js UI implementation in Breeze. Using this framework, you can build Laravel applications that act as backends and JavaScript frontends using Laravel Sanctum authentication.

Inline Blade rendering

If you need to convert a Blade template to HTML, you can now do it with Blade inline.

New query builder interface

The new query builder interface in Eloquent makes it possible to import Eloquent suggested queries. In the past, it was difficult to tell if you were dealing with , or for developers to guess what to fix whenever a TypeError popped up.

Implicit route bindings with enums

You can now enter hints with a PHP enum in your Laravel. Then Laravel will only invoke the variable in the enum that is valid in the URI and will return a 404 if one of the enums is not found.

Use in router

Forced scope route bindings

Laravel 9 can dynamically scope queries to retrieve a model nested by its parent using conventions to guess inheritance relationship names. For example:

You can also use scope constraints

Bootstrap 5 pagination views

Instead of writing your own pagination you can paginate with pagination views in Bootstrap 5.

New helpers

Laravel 9 is using PHP 8, IlluminateSupportStr its facade will use PHP 8 string functions, which comes with several new methods, including str_contains , str_starts_with and str_ends_with . New helpers include append and snake .

Share the news now

Source : Viblo