Introducing

Laravel 11: A Sneak Peek into the Future


The Laravel community is eagerly awaiting the release of Laravel 11, which is slated for Q1 of 2024. Taylor Otwell, the creator of Laravel, has already shared some exciting new features and improvements in his recent Laracon keynote. Let's take a deep dive into what we can expect from Laravel 11.

A Fresh Take on Directory Structure

The upcoming Laravel 11 is set to introduce a more streamlined directory structure. However, keep in mind that these are still in the beta stage and may undergo changes. Here's what we know so far:

  • Controllers will no longer extend anything by default.
  • The middleware directory is being phased out. Laravel currently includes nine middleware, many of which you may never modify. If you need to customize them, you can do so in the App/ServiceProvider. Here's an example:
public function boot(): void
{
    EncryptCookies::except(['some_cookie']);
}
  • Http/Kernel is being removed. Most of the tasks you could previously perform in the Kernel can now be accomplished in the Bootstrap/App.
return Application::configure()
    ->withProviders ()
    ->withRouting(
        web: __DIR__.'/../routes/web.php'
        commands: __DIR__.'/../routes/console.php',
    )
    ->withMiddleware(function(Middleware $middleware) {
        $middleware->web(append: LaraconMiddleware::class):
    })

Changes in Model Casts

In Laravel 11, model casts will be defined as a method rather than a property. This allows for more flexibility, such as calling other methods directly from the casts. Here's an example using Laravel 11's new AsEnumCollection:

protected function casts(): array
{
    return [
        'email_verified_at' => 'datetime',
        'password' => 'hashed',
        'options' => AsEnumCollection::of(UserOption::class),
    ];
}

Revamped Configurations

Laravel 11 is set to introduce a significant overhaul to its configuration system. Instead of multiple config files, Laravel 11 will adopt a cascading approach, where all configuration options are inherited from a higher level. The .env file will be expanded to include all the options you'd want to set.

In addition, Laravel 11 will introduce a new config:publish command, allowing you to retrieve any specific configurations you might need. The new cascading feature will enable you to easily remove any options you don't want to customize, ensuring a more streamlined and tailored configuration experience.

Route Changes

By default, Laravel 11 will only have two route files: console.php and web.php. If you want to include API routes, you'll need to opt-in by running php artisan install:api, which will provide you with the API routes file and Laravel Sanctum functionality.

Similarly, for websocket broadcasting, you can enable it using php artisan install:broadcasting. This command will set up the necessary files and configurations for websocket broadcasting in your Laravel application.

Goodbye to Console Kernel

In Laravel 11, the Console Kernel is no longer required. Instead, you can directly define your console commands within the routes/console.php file.

PHP Version Requirement

Laravel 11 applications will now require a minimum PHP version of 8.2. If you are running an older version of PHP, it's a good time to consider upgrading.

Laravel Support Policy

For all Laravel releases, bug fixes are provided for 18 months and security fixes are provided for 2 years. For all additional libraries, including Lumen, only the latest major release receives bug fixes.

Conclusion

Laravel 11 is shaping up to be a major leap forward for the Laravel community. The changes and improvements mentioned above are designed to enhance your workflow and make Laravel more efficient and user-friendly. However, these features are still in beta and may change as we approach the release date. We'll keep you updated as more news comes in. Stay tuned!

Tags:
PHP 8.2
Laravel 11