What's new coming to Laravel 11

What's new coming to Laravel 11

Laravel 11 is not scheduled to be released yet, but some new features have been shared out. Let's have a look at all these features.

 

 

1. Folder Structure

 

So far, these are only beta versions at the moment. They may change, but for now, here's  what to expect...

Controllers no longer extend anything by default.

No more middleware directory. Laravel currently has  nine middlewares and many that you would never customize. However, if you do want to customize them, it will be moved to the App/ServiceProvider.

 

For example:

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

 

 

 

2. No More Http/Kernel

 

Before laravel 11 most of the things you used to do in the Kernel, but now you can do all these things in the Bootstrap/App.

 

Example:

return Application::configure()
    ->withProviders ()
    -›withRouting(
        web: __DIR__.'/../routes/web.php'
        commands: __DIR__.'/../routes/console.php',
    )
    ->withMiddleware(function(Middleware Smiddleware) {
        $middleware->web(append: LaraconMiddleware::class):
    })

 

 

 

3. Model casts changes

 

Model casts are now defined as a method instead of a property. When defined as a method we can do rest of the things, like call other methods directly from the cast.

 

Here is an example of using the new Laravel 11 AsEnumCollection

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

 

 

 

 

4. Config Changes

 

Laravel has many configaration files, and Laravel 11 remove them, and all config options cascade down. The .env file is expanded to include all the options you'd want to configure.

 

To pair with this is a new config:publish command so you can bring back any config you might want. Even if you change them back, the new cascading feature lets you to remove any option you don't want to customize.

 

 

 

5. Slimmed default Migrations

 

When you install a new Laravel application, it comes with few default migrations file from 2014 and 2019. Now those dates have been removed and moved into just two files.

 

 

 

6. Route Changes

 

By default, there will be only two route files, console.php and web.php. API routes will now become opt-in via php artisan install:api, giving you the API routes file and Laravel Sanctum.

The same with websocket broadcasting, php artisan install:broadcasting.

 

 

 

 

7. Console kernel removed

 

The Console Kernel is removed, and you'll be able to instead define your console commands right in routes/console.php.

 

 

 

8. PHP 8.2 minimum required

 

This was an early decision, but Laravel 11 application require at least  PHP 8.2. If you are using an older version of PHP, now is the time to update it. 

 

 

Conclusion

 

All of these features are currently considered beta versions in Laravel 11 and are designed to improve your workflow.

Tags

  • Share This:

Comments - 1

xgenious suzon

I found this article very informative. Thanks for sharing with us and keep publishing more articles like this.

Jul 26, 2023

WebJourney

Thanks to like our content.

Jul 28, 2023