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

Reading Time: 9 minutes
158 Views

Today, I’m excited to walk you through the anticipated features of Laravel 11 in this tutorial. I’ll be highlighting the significant updates and enhancements expected in this upcoming version.

Laravel’s development team traditionally unveils new versions annually, typically in February, packed with an array of innovative features. These updates aim to empower developers with tools for building more professional and streamlined web applications.

In this post, I’ll be showcasing the latest updates and improvements slated for Laravel 11.

Let’e get started.

Laravel 11 “Release Date”

As per Laravel’s official website and Support Policy, Laravel 11 is set to unveil its newest iteration on February 6, 2024. It’s important to note that Laravel’s core team follows the Semantic Versioning approach, with major updates typically rolling out annually in the first quarter. Stay tuned for the latest enhancements and features in this highly anticipated release.

Now, let’s see the new updates and features of Laravel 11.

No Support For “PHP 8.1” in Laravel 11

With the release of Laravel version 11, a significant change is observed as it discontinues support for PHP 8.1. This decision is based on the expectation that by the launch of Laravel 11, PHP 8.2 will have achieved full stability, while PHP 8.3 will also be in a stable state.

Therefore, to utilize Laravel 11, it will be necessary to install either PHP 8.2 or PHP 8.3 version.

Laravel 11 will More Minimalistic Application Skeleton

In Laravel 11, an optimized application structure has been introduced, aimed at reducing redundant code and streamlining development workflows. This enhancement promises greater efficiency for both business owners and developers alike.

Upon installation of Laravel 11, users will encounter an ultra-minimalistic application skeleton, exemplifying the framework’s commitment to simplicity and improved development experiences.

The latest changes in Laravel 11 bring about notable optimizations and enhancements.

  • In the AuthServiceProvider, the framework now automatically discovers and removes $policies, streamlining the authentication process.
  • The inclusion of SendEmailVerificationNotification in the EventServiceProvider is no longer required, as it is automatically registered by the base EventServiceProvider. Additionally, Laravel now defaults to enabling auto-event discovery.
  • The BroadcastServiceProvider has been rendered non-essential and subsequently removed. As a result, the framework no longer automatically loads the routes/channels.php file.
  • The improvement of RedirectIfAuthenticated is now facilitated by the framework’s core functionality.
  • The Authenticate middleware no longer invokes the redirectTo() method for JSON routes, eliminating the need for redundant ternary checks.
  • Several middleware such as EncryptCookies, PreventRequestsDuringMaintenance.php, TrimStrings, TrustHosts, TrustProxies, ValidateCsrfToken, and ValidateSignature have been removed from the skeleton structure, streamlining the middleware configuration process.
  • Custom Artisan functions are now integrated into Laravel 11, eliminating the need to manually use the load() method in the console.
  • The deletion of the routes/console.php file marks a significant change, as special commands can now be directly placed in the console kernel.
  • The AuthorizesRequests and ValidatesRequests traits have been removed from the foundational controller, streamlining controller structure.
  • The bootstrap/app.php file has been streamlined to just three lines of code, reducing complexity and improving readability.
  • Laravel 11 has removed the exception handler, possibly indicating a shift in error handling or a different approach to managing exceptions.

Laravel 11 Add Dumpable Trait(dump() and dd() with Objects)

In Laravel 11, a new Dumpable Trait has been introduced, providing developers with a convenient method to dump objects. This enhancement proves particularly useful for debugging Laravel Eloquent query builders, allowing for efficient troubleshooting of relational databases and complex data structures.

So, let’s see the simple example code:

<?php
   
namespace App\ValueObjects;
   
use Illuminate\Support\Traits\Dumpable;
use Illuminate\Support\Traits\Conditionable;
   
class Student
{
    use Conditionable, Dumpable;
   
    /* ... */
}
   
$student = new Student;
   
// Before:
$student->foo()->bar();
   
// After:
$student->foo()->dd()->bar();

Model::casts() Method Live in Laravel 11

In Laravel 11, defining model castings has become even more convenient with the introduction of the casts() method in your model. This feature allows you to utilize static methods from the class performing the casting, providing greater flexibility and control over data transformation within your application.

Let’s see the old one and new one with the bellow code:

<?php
  
namespace App\Models;
  
use App\Enums\UserRole;
use Illuminate\Database\Eloquent\Model;
 
class User extends Model
{
    /* OLD method */
    protected $casts = [
        'role' => UserRole::class,
    ];
  
    /* NEW Method */
    protected function casts() : array
    {
        return [
            'role' => UserRole::class,
        ];
    }
}

Laravel 11 Removed Config Files By Default

In Laravel 11, there’s been a shift in default configuration management, as the framework no longer includes config files by default. Instead, additional variables have been added to the .env file, allowing for configuration directly from there.

However, if you wish to restore all config files, you can do so by running the following command:

Publish All Config File

php artisan config:publish

Publish Specific Config File

php artisan config: publish database

Laravel 11 Slimmed Default Migrations Names

In Laravel 11, there will be a change in the naming convention for migrations. Previously, migration names included the creation date, but in the new version, they will adopt a more structured naming convention.

Here’s an example of the new naming format:

OLD Migrations Name

migrations
├── 2014_10_12_000000_create_users_table.php
├── 2014_10_12_100000_create_password_reset_tokens_table.php
├── 2019_08_19_000000_create_failed_jobs_table.php

NEW Migrations Name

migrations
├── 0001_01_01_000000_create_users_table.php
├── 0001_01_01_000001_create_jobs_table.php

Laravel 11 Removed Console Kernel

In Laravel 11, the console kernel file has been removed, simplifying the process of registering console commands. Now, you can declare console commands directly without the need for registration in the kernel file.

Here’s an example of how it can be done:

php artisan make:command TestCommand
// Console command [app/Console/Commands/TestCommand.php] created successfully.  

routes/console.php

Schedule::command('app:test-command')->hourly();

Laravel 11 added more changes but i share with you some of it.

That’s it.

We hope this article helped you to learn about “What’s New in Laravel 11: New Features and Latest Updates” in a explained way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more