Laravel 9 is Released! Top Features & Updates of Laravel 9

Laravel 9 is Released! Top Features & Updates of Laravel 9

Laravel 9 is here, and with many new features, including Flysystem 3.x, Symfony mailer integration, Scout database engine, and many more.

Before we jump into a new major version, let’s recap what Laravel is. Its Advantages and Features.

A Quick Recap – What Is Laravel?

Laravel is an open-source PHP-based web application framework that is entirely free to use. This PHP framework comes with expressive, elegant syntax and offers an enjoyable experience to the developers in creating a web application.

Laravel would be much easier to handle by developers who are familiar with core PHP and advanced PHP. This web application framework follows a model-view-controller and incorporates other popular PHP frameworks & programming languages like Codeigniter, Yii, Ruby & Rails.

Why Use Laravel? Advantages Listed!

  • Laravel framework builds a scalable web application
  • Components reusability saves a lot of time in designing a web application
  • Organizing & managing resources become easier with the presence of namespaces & interfaces

Top Features of Laravel

Laravel PHP framework is a powerful tool for building large and robust web applications. It comes with various built-in functionalities & features, yet it is highly accessible. Here are the 6 best features of Laravel that make it such a popular web framework among web application developers.

  • Template Engine: The presence of light-weight enables developers to build wonderful site designs with dynamic content seeding. Also, it offers robust structures and distinctive sections for complex layouts.

  • MVC Architecture: The MVC architecture pattern has a lot of built functions that play a handy role in separating business logic & presentation layers. Also, it improves performance, and scalability and provides security.

  • Eloquent Object Relational Mapping (ORM): The eloquent ORM feature enables developers to write database queries in PHP instead of SQL.

  • Security: Laravel uses hashed & salted mechanism for passwords along with Bcrypt Hashing Algorithm, so it provides very strong web application security.

  • Artisan: The presence of the built-in command-line tool Artisan allows developers to manage databases easily. Also, it empowers developers to build their commands for automating repetitive tasks.

  • Pre-Installed Libraries & Modular: Unlike other PHP frameworks, this Laravel framework comes with built-in libraries & modular which adapt PHP principles.

What’s new in Laravel 9?

Similar to Laravel 6, Laravel 9 provides long-term support and longest maintenance and support guidance. It offers 18 months of support to fix bugs and two years of security support. that will remain until February 2024 and 2025 respectively.

screenshot-laravel.com-2022.06.08-10_43_13.png

New Features in Laravel 9

1. Symfony Mailer

Unlike the previous version, Laravel 9 doesn't maintain any separate library for sending emails. Instead, it uses its Symfony mailer.

2. Flysystem 3.x

Flysystem gets upgraded in Laravel 9, and because of that, it empowers all interactions that happen on the filesystem at the storage facade.

3. Improved Eloquent Accessors/Mutators

Unlike the old version, this Laravel 9 has its way of defining eloquent accessors & mutators through type-hinting a return type using a single, non-prefixed method.

Use Illuminate\Database\Eloquent\Casts\Attribute; Public function name(): Attribute

{
    return new Attribute(

get: fn ($value) => strtoupper($value),

set: fn ($value) => $value,
    );
}

4. Enum Eloquent Attribute Casting

This enum eloquent attribute casting feature of Laravel 9 enables you to cast values to your attributes in the PHP model. Once it is done, the specific attributes will cast automatically whenever you interact.

use App\Enums\ServerStatus;
/**
 * The attributes that should be cast.
 *
 * @var array
 */
protected $casts = [

'status' => ServerStatus::class,
];

5. Implicit Route Binding with Enums

Laravel 9 comes with the ability to type-hint an enum on route definition. However, it invokes the route only if it has a valid enum value. Else it will highlight the HTTP 404 error response.

6. Forced Scoping of Route Bindings:

With this advanced version of Laravel 9, you can instruct the framework to scope “Child” bindings without any custom key.

use App\Models\Post;
use App\Models\User;
 Route::get('/users/{user}/posts/{post}', function (User $user, Post $post) {
return $post;
})->scopeBindings();

7. Controller Route Groups

With this feature, you can define a common controller of a route using a controller method within the group. However, for defining routes you are supposed to provide a controller to invoke.

use App\Http\Controllers\OrderController;
Route::controller(OrderController::class)->group(function () {
    Route::get('/orders/{id}', 'show');
    Route::post('/orders', 'store');
});

8. Full-Text Indexes / Where Clauses

Laravel 9 uses ‘whereFullText’ and ‘orWhereFullText’ methods for generating full text indexes in column definitions instead of using ‘fullText’ methods while using MySQL or PostgreSQL.

9. Laravel Scout Database Engine

This feature allows developers to use scout’s ‘database’ engine for interacting with small or medium-sized databases instead of using dedicated search services. The scout’s ‘database’ engine uses ‘where like’ clauses and full-text indexes for filtering the results picked from the existing databases.

10. Rendering Inline Blade Templates

Laravel 9 uses ‘render’ method of blade facade for transforming blade templates into a valid HTML.

use Illuminate\Support\Facades\Blade;
return Blade::render('Hello, {{ $name }}', ['name' => 'John Garter']);

Similarly, it uses ‘rendercomponent’ method for rendering class components.

use App\View\Components\HelloComponent;
return Blade::renderComponent(new HelloComponent('John Garter'));

11. Slot Name Shortcut

With this Laravel 9 feature, you can able to specify the slot’s name using a comfortable, shorter syntax.

<x-slot:title>
    Server Error
</x-slot>

12. Checked / Selected Blade Directives

This feature of Laravel 9 ‘@checked’ and ‘@selected’ directives indicate the provided HTML checkbox in ‘checked’ and the given select option is ‘selected’.

<input type="checkbox"
name="active"
        value="active"

@checked(old('active', $user->active)) />
<select name="version">
    @foreach ($product->versions as $version)
        <option value="{{ $version }}" @selected(old('version') == $version)>
            {{ $version }}

</option>
    @endforeach
</select>

13. Bootstrap 5 Pagination Views

Laravel 9 comes with the built-in bootstrap 5 pagination view feature. This allows developers to call paginator’s method ‘useBootstrapFive’ within the ‘boot’ method.

use Illuminate\Pagination\Paginator;
/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{

Paginator::useBootstrapFive();
}

14. Improved Validation of Nested Array Data

This feature of Laravel 9 allows developers to access the value of nested array elements using the ‘Rule:: forEach’ method. Here the forEach method is used to invoke the iteration of the array attribute.

use App\Rules\HasPermission;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
$validator = Validator::make($request->all(), [
    'companies.*.id' => Rule::forEach(function ($value, $attribute) {
        return [
            Rule::exists(Company::class, 'id'),
            new HasPermission('manage-company', $value),
        ];
    }),
]);

15. Laravel Breeze API & Next.js

Laravel 9 comes with Laravel Breeze starter kit with ‘API’ scaffolding mode and complimentary Next.js and frontend implementation. With this starter kit, developers can utilize the authenticated API and JS frontend for building efficient Laravel applications.

16. Improved Ignition Exception Page

The new version of Laravel 9 comes with an improved open-source exception debug page Ignition. In addition, it has pre-built light/dark themes, a custom ‘open in editor’ function, and many more.

17. Improved route: list CLI Output

Laravel 9 version comes with a well-improved ‘route:list’ CLI output. Owing to that, it delivers a beautiful experience to the developers while exploring route definitions.

18. Test Coverage Using Artisan test Command

The Artisan ‘test’ command has received a new option in this Laravel 9 version in form of ‘--coverage’. This allows developers to explore the code coverage for building a strong application.

PHP artisan test –coverage
`

19. Soketi Echo Server

Laravel 9 gets assisted with the Soketi Echo Server which is a compatible web socket server. The open-source soketi echo server is a perfect alternative for applications that uses pusher and ably for maintaining web socket servers.

20. Improved Collections IDE Support

The updated version of Laravel 9 comes with well-improved ‘generic’ style component definitions and IDEs like ‘PHPStorm’ along with static analysis support like ‘PHPStan’. This enables developers to understand the Laravel native collections better.

21. New Helpers

Laravel 9 version comes with two additional convenient helper functions ‘Str’ and ‘to_route’.

  • ‘Str’ Function: This function returns ‘Illuminate\Support\Stringable´ instantly which is equivalent to the ‘Str::of’ method.

  • ‘‘to_route’ Function: This function is used to generate an HTTP response during the redirect route. With this developers can find an expressive way to redirect routes and controllers.

The very rich set of functionalities and features of Laravel enables web developers to complete their application development process much quicker and prevents web attacks by offering high security.

Check out this official video to know everything about the latest Laravel 9 release in just 45 minutes.