Laravel 11 is scheduled to be released in 2024, and since Laravel 9 and Laravel 10 were both released in February, it seems like it’s about time.
I tried Laravel11. If I sum up my impression in one word, “Fewer files, cleaner! Let me show you the changes from Laravel 10.
Please note that the changes are subject to change.
In the past, the features that were announced before the release of Laravel and the contents after the release have changed. It seems that developers have a lot of work to do.
Laravel11 Install
You can install a Laravel11 project with the following command. Note that PHP 8.2 or higher is required for Laravel11.
1 |
composer create-project --prefer-dist laravel/laravel laravel-dev dev-master |
By the way, in Laravel 10, PHP was OK with 8.1 or higher.
Summary of new features of Laravel 11
From here, I would like to introduce some of the changes and features that are likely to be implemented in Laravel 11.
Middleware is gone in Laravel 11!
The first thing that seems to have a big impact is the loss of middleware by default.
【app/Http】
In the past, there were 9 middleware files in app/Http/Middleware by default, but in Laravel 11, the whole folder of middleware has disappeared.
But don’t worry. We can use middleware!
Middleware files simply do not appear by default, but you can still use them as before.
According to Taylor
Many default middleware, such as cookie-encrypting middleware, are rarely modified by the user. It would be nice, then, if it could be easily customized only when needed.
*Simplified comments in videos
I agree. There are not many cases to customize the default middleware.
Middleware can be created by the following command as before. After creation, the middleware file will be created in app/Http/Middleware as before.
1 |
php artisan make:middleware TestMiddleware(Middleware Name) |
Laravel 11 changes where middleware is registered
In Laravel 11, the kernel.php file used for middleware registration has disappeared along with the middleware.
From now on, the location for registering created middleware seems to be bootstrap/app.php. This is a location that we have not had much opportunity to use so far.
【bootstrap/app.php】
api and console are missing from routes.
If you look at the bootstrap/app.php file above, you will see that routes/api.php and routes/channels.php are commented out.
The api.php and channels.php files are also missing from the routes folder.
【routes】
Config folder is also empty
Furthermore, the config folder is also empty. This is also assumed to be because there are few changes to be made by default.
When editing is necessary, the vendor:publish command can be used to create a config file.
When editing the published config file, it seems that only the parts that need to be updated should be left. If there is no special mention, the default values will be used.
This reduces the amount of code to be written.
Model casts changed from static properties to methods
It appears that casts will be function, whereas it is static properties in Laravel 10.
【User.php(Laravel10)】
1 2 3 4 |
protected $casts = [ 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; |
【User.php(Laravel11)】
1 2 3 4 5 6 7 |
protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; } |
By becoming a function, it will be possible to add processing, etc.
Migration files are also compact
In Laravel 11, the migration files are also more compact.
In Laravel 10, there were four migration files by default, including the users table.
In Laravel 11, there is code to create two tables in one file. The tables created by default are also slightly different.
【Laravel11 database/migrations】
No Console
I am no longer surprised, but app/Console is no longer there by default. This is used for command processing, etc., but since it is not used in many cases, it is assumed that it is now hidden by default.
The main reference source for this article
This article is based on a video of a talk by Taylor Otwell (creator of Laravel) at the Laravel conference (Laracon) on July 19, 2023. For the original video, please see below.
The video is used as a reference to actually create and test a project in Laravel 11 before its release.
Finally
In a word, I have the impression that Laravel 11 has achieved a “cleaner & slimmer” look.
Files with default settings that are rarely changed are hidden, and I feel that they are easier to see.
There may be more changes at the time of release, and I will keep updating this page according to the official announcement of Laravel.
If you are interested in Laravel 11, please come back to see what’s going on.