The Laravel community has been eagerly anticipating the release of Laravel 11, the next major version of the popular PHP framework. With each release, Laravel continues to evolve, introducing new features, improvements, and optimizations. In this blog post, we'll take a closer look at some of the exciting changes that come with Laravel 11. According to the Support Policy, Laravel 11 is scheduled to be released on February 6th, 2024.

In this tutorial, I will discuss what is going to be released in Laravel 11 what will be removed,d and what we will get as new features. Laravel 10 will receive bug fixes until August 6th, 2024, and security fixes until February 4th, 2025.

whats-new-in-laravel-11

What’s new in Laravel 11: features and changes

Laravel 11 introduces a more minimalistic application skeleton. Laravel 11 is coming with a slimmer application skeleton. Look at that, the below classes and services are going to be removed in Laravel 11. All the features Laravel 11 is going to remove:

  1. Laravel 11 will move PHP 8.1 to PHP 8.2. Laravel 11.x requires a minimum PHP version of 8.2.
  2. In App\Providers\AuthServiceProvider, the $policies property has been removed, as the framework automatically discovers them.
  3. In App\Providers\EventServiceProvider, the SendEmailVerificationNotification is no longer necessary, as the base EventServiceProvider is registering it. You will also notice that auto-event discovery is now enabled by default
  4. App\Providers\BroadcastServiceProvider has been removed.
  5. RedirectIfAuthenticated is now simpler thanks to the base one in the framework’s internals.
  6. The Authenticate middleware will no longer call redirectTo() for JSON routes. This removes an unnecessary ternary check.
  7. EncryptCookies, PreventRequestsDuringMaintenance, TrimStrings, TrustHosts, TrustProxies, ValidateCsrfToken, and ValidateSignature middlewares have been removed from the skeleton.
  8. Custom Artisan commands will be loaded automatically. The console kernel does not need to call the load() method.
  9. The routes/console.php has been removed.
  10. The AuthorizesRequests and ValidatesRequests traits have been removed from the base controller.
  11. The bootstrap/app.php file has been shrunk to just three lines of code.
  12. The exception handler has been removed.

New features in Laravel 11:

Config Folder

In Laravel 11, there have been significant changes to the configuration system. Instead of having a bunch of config files, Laravel now adopts a cascading approach, where configuration options are inherited from a higher level. The application .env file has been improved to encompass all the necessary settings we may wish to configure.

API and Broadcasting Route

There will be no API-related route in Laravel 11. If you want API routes to be included in your application, you’ll need to opt-in by running “php artisan install:api” which will provide us with the API routes file and Laravel Sanctum functionality with necessary configurations.

Similarly, for web socket broadcasting, we can enable it using php artisan install:broadcasting This command will set up the necessary files and configurations for web socket broadcasting in our Laravel 11 application.

Middleware Directory

In Laravel 11, the middleware directory will be removed. Laravel 10, comes with nine middleware, and most of them are unlikely to be customized. However, if you do wish to customize any middleware, we can now do so within the App/ServiceProvider.
For example:

<?php

public function boot(): void
{
    EncryptCookies::except(['some_cookie']);
}

Dumpable trait

Laravel 11 is going to release the Dumpable trait and The trait allows Laravel users and package authors to include debugging methods easily within their classes by utilizing this trait.

Here’s a code example showing how it can be used:

<?php
 
namespace App\ValueObjects;
 
use Illuminate\Support\Traits\Dumpable;
use Illuminate\Support\Traits\Conditionable;
 
class Address
{
    use Conditionable, Dumpable;
 
    // ...
}

$address = new Address;
 
// Before:
$address->foo()->bar();
 
// After:
$address->foo()->dd()->bar();

 

The new and more convenient Model::casts() method is going to be released in Laravel 11. Usually, in Laravel, you declare attribute casting in an Eloquent model like this:

<?php

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

 

But in Laravel 11, we can now define your casting through a casts() method in your model, giving you a chance to use static methods from the class doing the casting. This is how it looks:

<?php

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

 

Even, we can now also specify your casts as an array:

<?php

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],
        ];
    }
}

 

Conclusion

Laravel 11 brings exciting features and improvements to the table, further solidifying its position as a leading PHP framework. Whether you're a seasoned Laravel developer or just getting started, exploring the latest release will open up new possibilities for your web development projects.

To get started with Laravel 11, head over to the official Laravel website and check out the documentation.

Category : #laravel

Tags : #laravel , #laravel 11