BLOG

Back
What’s New in Laravel 11: Upcoming Features and Updates

What’s New in Laravel 11: Upcoming Features and Updates

Posted on November 27, 2023

By Divya Sharma

1701081669.webp
1701081737.png

Quick Summary:

Laravel is the knight in shining armor for business owners prioritizing security for their web application development. Respecting this factor, the core team at Laravel is ready with another bombastic release of the renowned PHP web application framework, Laravel 11. So, here we are again to update you with the latest facts about What’s New in Laravel 11, along with the latest updates and features that you should look forward to for your business. Also, these factors will help you take the final stand if you should upgrade your existing Laravel to the latest Laravel version.

Table of Contents

Laravel 11 Release Date

Referring to the latest update on the official website of Laravel, the Support Policy mentions that the latest version of Laravel 11 release date is on February 6, 2024, as we know that the Laravel core team follows the Semantic Versioning methodology that entails that the major updates to the framework are released once a year during the first quarter. However, it doesn’t mean your existing applications should be updated immediately to the latest Laravel version.

The Laravel framework was last released (LTS or Long Term Support) in version 6, but each major version possesses two years of updates; this enables enough time to get your existing codebase in check and upgrade it accordingly. According to the official Laravel documentation, Laravel 10 will receive bug fixes until August 6, 2024, and security fixes until February 4, 2025.

Version PHP Release Bug Fixes Until Security Fixes Until
10 8.1 February 14, 2023 August 6, 2024 February 4, 2025
11 8.2 Q1 2024 August 5, 2025 February 3, 2026

What’s New in Laravel 11: Latest Features and Updates

The team at Laravel understands the importance of the latest features and updates being introduced within the system. However, they strive to deliver the best to the developers and the business owners. This is why using the latest version of the framework or its components is always preferred. The same is the case with the latest Laravel v11, which has many updates that can benefit your business under several heads. Let’s proceed with what Laravel 11 has with this year’s latest updates.

No Support For PHP 8.1 in Laravel 11

The first and foremost change that Laravel version 11 will bring is dropping the support for PHP 8.1. The reason is that the PHP 8.2 will be fully established when Laravel 11 is up for use, and the PHP 8.3 will also be stable. Therefore, with 2 upgraded versions running within the market, the need for an older version, PHP 8.1, is unnecessary. However, again, it is not a mandate to upgrade to the latest version instantly, but you can take a thorough testing approach. You can update the existing applications gradually, but upgrading to the latest version is a great choice.

More Minimalistic Application Skeleton

Laravel 11 possesses a slimmer application skeleton. The intent here is to involve less boilerplate code to deal with. This approach will benefit the business owners and developers to deal with less code, leading to faster development. Talking about the changes made in-depth, they are all as follows:

  • Within the ‘AuthServiceProvider,’ the ‘$policies’ are removed as the framework discovers them automatically.
  • In the ‘EventServiceProvider,’ the ‘SendEmailVerificationNotification’ is no longer necessary, as the base ‘EventServiceProvider’ is registering it. Also, you will notice that the auto-event discovery is now enabled by default.
  • ‘BroadcastServiceProvider’ is not needed anymore and, therefore, is removed. The framework is not automatically loading the routes/channels.php file.
  • ‘RedirectIfAuthenticated’ is simpler due to the base one in the framework’s internals.
  • The ‘Authenticate’ middleware now does not call the ‘redirectTo()’ for the JSON routes, thereby removing the unnecessary ternary checks.
  • All the ‘EncryptCookies,’ ‘PreventRequestsDuringMaintenance.php,’ ‘TrimStrings,’ ‘TrustHosts,’ ‘TrustProxies,’ ‘ValidateCsrfToken’ and ‘ValidateSignature’ middleware are removed from the skeleton structure.
  • The Custom Artisan is loaded automatically with Laravel 11, and the console does not need to call the ‘load()’ method.
  • The routes/console.php have been removed. The closure-based artisan commands can now be registered in the console kernel only.
  • Various other migrations are either consolidated into a single file or removed.
  • The ‘AuthorizesRequests’ and ‘ValidatesRequests’ traits have been removed from the base controller.
  • The bootstrap/app.php file has been reduced in size, now with only three lines of code.
  • The exception handler is also removed in the Laravel v11.

The New Dumpable Trait - (dump () and dd () from your objects)

The core intent behind this pull request is to replace the current dd and dump methods in most Laravel classes, and it will introduce a new Dumpable trait as well. Also, the trait enables Laravel users and package authors to include debugging methods easily within their class by utilizing this trait. Let us take a glimpse of an example to use it:

Copy Text
foo()->bar();
 
// After:
$address->foo()->dd()->bar();

Also, this pull request is specifically intended for Laravel 11.x as it requires modifications to the signature of several methods. For consistency across the entire codebase, adding the …$args to the debugging methods was added. However, it is still preferred for the Laravel 11.x version.

Model::casts() Method Live in Laravel 11

In the latest version of Laravel, Model casts are now defined as a method instead of a property. When defined as a method, it enables performing other things, such as calling other methods directly from the casts.

Generally, Laravel requires declaring attribute casting in an eloquent model as given below:

Copy Text
class User extends Model
{
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}

However, with Laravel 11 you can easily define your casting through a ‘casts()’ methods in your model that offers you a chance to use static methods from class doing the casting as illustrated below:

Copy Text
class User extends Model
{
    protected function casts(): array
    {
        return [
            'foo' => AsCollection::using(FooCollection::class),
        ];
    }
}


Also, you can now specify your casts as an array, as given below:

Copy Text
class User extends Model
{
    // Even in the old $casts property!
    protected $casts = [
        'foo' => [AsCollection::class, FooCollection::class],
    ];
 
    protected function casts() : array
    {
        return [
            'foo' => [AsCollection::class, FooCollection::class],
        ];
    }
}

The ‘casts()’ method is prioritized over the ‘$casts’ property.

Also, these changes are non-breaking, which will not affect the current code when you upgrade to Laravel 11.

Config Changes

The older versions of Laravel possessed multiple config files, and Laravel v11 has come up with these files removed and all the config options being cascaded down. The ‘.env’ has been expanded to include all the options you want to set or configure.

Further, pairing with Laravel 11 comes with a completely new ‘config:publish’ command that enables you to bring back any config that you need. And, even after bringing them back, the new cascade feature enables you to remove every option you don’t want to customize, thereby ensuring a more streamlined and tailored configuration experience. Considering a common example, running ‘artisan config:publish database‘ generates a dedicated database config. File, precision, and organization at ease.

Copy Text
// To publish all the config files
php artisan config:publish

// Specific config file
php artisan config:publish database

Slimmed Default Migrations

In Laravel v11, when creating a new Laravel application, the default migrations from 2014 and 2019 will undergo a significant reorganization. Instead of being spread across multiple migration files, these migrations will be consolidated into two files only.

This will allow the developers initiating a new Laravel project to have a cleaner and more streamlined database/migrations directory, enhancing the overall development experience and project maintainability.

Confused! About Upgrading To Laravel Version 11?

Hire Laravel Developers with industry-wide experience to build next-gen Laraval solutions that help you get the best out of your project.

Console Kernel (Removed)

After removing the HTTP Kernel, the Console Kernel is also removed, and in place of that, a new approach is introduced. That means in place of having a dedicated Console Kernel file, developers will be responsible for defining their console commands directly in the routes/console.php file.

The routes/console.php file traditionally defined the Artisan commands as closures will now work as the primary location for registering all console commands. This change aims to simplify the structure of Laravel applications and offer a more simplified and consolidated way to manage console commands. By removing the Console Kernel and moving the command definitions to routes.console.php, Laravel aims to streamline the application’s configuration and reduce unnecessary files. This new approach enables the developers to have a clear and centralized view of all the console commands, making it easier to manage and maintain them throughout the development process.

Considering the default setting in Laravel, there will be two route files: console.php and web.php. If you wish API routes to be included, you must opt-in by running the ‘php artisan install:api’ that will offer you the API routes file and the Laravel Sanctum functionality.

Similarly, for the websocket broadcasting, you can use the command ‘php artisan install:broadcasting.’ This command will set up the necessary files and configurations crucial for the websocket broadcasting in your Laravel applications. Collectively, these changes will contribute to a radical shift towards a more modular and customizable application structure.

Other GitHub Pull Requests Hinting At the Latest Laravel 11 Features

Here is a list of the other probable Laravel 11 Features and Updates that we can expect in the latest version of Laravel 11.

Laravel 11 Other Features and Updates    
[10.x] Cursor pagination model casting bugfix #46707 Click Here
[10.x] Fix doc block type for dispatchAfterCommit queue property. #46704 Click Here
Add generic type hints to collections returned from Stringable methods #46702 Click Here
[9.x] withCount doesn’t use other database connection for joins when hasManyThrough #46675 Click Here
[11.x] Do not change relative path to absolute one #46668 Click Here
[10.x] Support array syntax for casts #46649 Click Here
[10.x] Add support for Attribute union return types #46624 Click Here
[10.x] Escaping functionality within the Grammar #46558 Click Here
[9.x] Return non-zero exit code for uncaught exceptions #46541 Click Here
[10.x] Configuration value injection #46530 Click Here
[10.x] Add pipe function to Process layer #46527 Click Here
[10.x] Update RedisTagSet now() to Carbon::now() #46396 Click Here
feat(sqs-fifo): add support for fifo type of sqs queue driver #46364 Click Here
[10.x] Named static methods for middleware #46362 Click Here
[10.x] Revert facade changes #46255 Click Here
[10.x] Command Input Validation #46037 Click Here
[11.x] Adds mail notifications using mailable #45943 Click Here

How To Install Laravel 11

To install Laravel v11, initially, you must specify the ‘-dev flag’ during the installation. Laravel can then be programmed to download and install only the master branch from the ‘laravel/laravel’ repository.

Copy Text
Laravel new hello-world-dev

However, if you prefer the hands-on installation experience, then your go-to choice is a Composer.

Copy Text
composer create-project -prefer-dist laravel/laravel hello-world dev-master