Laravel 11 is not scheduled to be released until the end of the year, but some new features have been shared out, and Taylor goes through some big new improvements in his Laracon keynote:
Streamlined Directory Structure
So far, these are just a beta preview. They might change, but as of now, here is what to expect...
Controllers no longer extend anything by default.
No more middleware directory. Currently, Laravel includes nine middleware and many you would never customize. However, if you do want to customize them, that is moved to the App/ServiceProvider. For example:
public function boot(): void
{
EncryptCookies::except(['some_cookie']);
}
No more Http/Kernel
Most of the things you used to could do in the Kernel you can now do in the Bootstrap/App.
return Application::configure()
->withProviders ()
-›withRouting(
web: __DIR__.'/../routes/web.php'
commands: __DIR__.'/../routes/console.php',
)
->withMiddleware(function(Middleware Smiddleware) {
$middleware->web(append: LaraconMiddleware::class):
})
Model casts changes
Model casts are now defined as a method instead of a property. When defined as a method we can do other things, like call other methods directly from the casts. Here is an example using a new Laravel 11 AsEnumCollection
:
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'options'=› AsEnumCollection::of(UserOption::class),
];
}
Config Changes
Laravel has a lot of config files, and Laravel 11 removes these, and all config options cascade down. The .env
has been expanded to include all the options you'd want to set.
To pair with this is a new config:publish
command so you can bring back any config you might want. Even with bringing them back, the new cascade feature allows you to remove every option you don't want to customize.
Slimmed default Migrations
When you start a new Laravel app, it comes with some default migrations from 2014 and 2019. These now will come with the dates removed and moved into just two files.
Routes 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
.
Console Kernel Removed
The Console Kernel is being removed, and you'll be able to instead define your console commands right in routes/console.php
.
PHP 8.2 minimum support
This was an early decision, but Laravel 11 apps require a minimum of PHP 8.2. If you are running an older version of PHP, now is a good time to get that upgraded.
Wrapup
So far, all these features are considered beta for Laravel 11 and are designed to improve your workflow. Things can and probably change, and we will keep this post updated as new features are announced.