![Laravel 11 New Features and Changes Laravel 11 New Features and Changes](https://steronpot.com/wp-content/uploads/2024/03/LARAVEL-11-1.png)
Laravel 11 New Features and Changes
Laravel 11 New Features and Changes: this is one of the most exciting versions of the framework for a long time. Quite a lot of changes and new features, let’s explore them!
1. Slim Skeleton
The most significant change for Laravel 11 is the more minimalistic application skeleton.
When you install a new Laravel project, the folder structure will look like this:
app/├── Http/│ └── Controllers/│ └── Controller.php├── Models/│ └── User.php└── Providers/└── AppServiceProvider.phpbootstrap/├── app.php└── providers.phpconfig…NOTE: These structure changes are OPTIONAL. They will be the default only for NEW projects. Older Laravel applications can have the old structure.
Removed folders:Â app/Console
, app/Exceptions
, app/Http/Middleware
.
Routes, Middlewares, and Exceptions are now registered in the bootstrap/app.php
 file.
bootstrap/app.php:
use Illuminate\Foundation\Application;use Illuminate\Foundation\Configuration\Exceptions;use Illuminate\Foundation\Configuration\Middleware;return Application::configure(basePath: dirname(__DIR__))->withRouting(web: __DIR__.’/../routes/web.php’,commands: __DIR__.’/../routes/console.php’,health: ‘/up’,)->withMiddleware(function(Middleware$middleware) {//})->withExceptions(function(Exceptions$exceptions) {//})->create();
Also, cleaned up routes
 folder. The files routes/channel.php
, routes/console.php
, and routes/api.php
 have been removed.
You can check the initial pull request [11.x] Slim skeleton to see more details on what was changed.
2. Removed Some Config Files
This change has a backstory. At first, when Taylor introduced slimmer skeleton, all config/
 files were removed. However, Taylor wasn’t happy with this change and introduced a slimmer config version.
So, if you look at the config/
 folder of Laravel 10, you will find these files missing in Laravel 11:
- config/broadcasting.php
- config/cors.php
- config/hashing.php
- config/sanctum.php
- config/view.php
But you can publish them manually, with this command:
php artisan config:publish
php artisan config:publish –all
Also, some config values inside the existing files were removed in favor of automation inside the framework itself.
Now, speaking about Sanctum and Broadcasting configuration…
3. API and Broadcasting: Installed Optionally
Laravel 11 has no routes/api.php
 file, and Sanctum isn’t installed by default. You can install the API scaffolding with the php artisan install:api
 artisan command.
When you run this artisan command, the routes/api.php
 file will be created and registered in the bootstrap/app.php
, and Laravel Sanctum will be installed. You must only add the Laravel\Sanctum\HasApiTokens
 trait to the User
 Model.
Similar to the API changes, broadcasting also became installable: to prepare the application, you can use the php artisan install:broadcast
 artisan command.
4. New Defaults: Pest and SQLite
With Laravel 11, there are a few new default settings.
Testing Framework: Pest
Taylor made a poll on X (Twitter), and the majority of the people voted for Pest to be the default testing framework, so it was changed.
Note: If you want to start with testing, we have a course Testing in Laravel 11 For Beginners where we specifically use Pest syntax first, but also have PHPUnit examples.
Default Database: SQLite
The default database for Laravel was changed to SQLite. You can check the pull request SQLite for local dev. Also, watch my YouTube video Upcoming Laravel 11: SQLite as Default Database about this change.
If you want to change the default database driver to MySQL, we have an article about it.
5. New “make:xxxxx” Commands
Laravel 11 comes with new make:
artisan commands. Now, you can create enums, interfaces, and classes.
php artisan make:enumphp artisan make:classphp artisan make:interface
You can check the syntax in GitHub pull requests:
6. Health Check
Laravel 11 comes with a new registered Route /up
.
return Application::configure(basePath: dirname(__DIR__))->withRouting(web: __DIR__.’/../routes/web.php’,commands: __DIR__.’/../routes/console.php’,channels: __DIR__.’/../routes/channels.php’,health: ‘/up’,)->withMiddleware(function(Middleware$middleware) {//})->withExceptions(function(Exceptions$exceptions) {//})->create();
Laravel defines the health route when setting the routes and fires the DiagnosingHealth
 Event.
src / Illuminate / Foundation / Configuration / ApplicationBuilder.php:
use Illuminate\Foundation\Events\DiagnosingHealth;use Illuminate\Support\Facades\View;class ApplicationBuilder{// …protectedfunctionbuildRoutingCallback(?string$web,?string$api,?string$pages,?string$health,string$apiPrefix,?callable$then){returnfunction()use($web, $api, $pages, $health, $apiPrefix, $then) {if (is_string($api) &&realpath($api) !==false) {Route::middleware(‘api’)->prefix($apiPrefix)->group($api);}if (is_string($health)) {Route::middleware(‘web’)->get($health, function() {Event::dispatch(newDiagnosingHealth);returnView::file(__DIR__.’/../resources/health-up.blade.php’);});}if (is_string($web) &&realpath($web) !==false) {Route::middleware(‘web’)->group($web);}if (is_string($pages) &&realpath($pages) !==false&&class_exists(Folio::class)) {Folio::route($pages, middleware: $this->pageMiddleware);}if (is_callable($then)) {$then($this->app);}};}// …}
The /up
 endpoint returns the response time.
7. Dumpable Trait
Laravel 11 introduces a new Dumpable
 trait. It is intended to replace the current dd()
 and dump()
 methods in most of the framework’s classes. Users and package authors can include this trait for easier code debugging.
Here is the usage example:
class Address{useConditionable, Dumpable;// …}
$address = new Address;$address->setThis()->setThat();$address->setThis()->dd()->setThat();
See the pull request on GitHub:Â [11.x] Adds Dumpable concern
8. Limit Eager Load
Laravel 11 will allow limiting eagerly loaded records natively, without external packages.
class User extends Model{publicfunctionposts(){return$this->hasMany(Post::class);}}
class Post extends Model{// …}
$users = User::with([‘posts’ => function ($query) {$query->latest()->limit(10);}])->get();
Before Laravel 11, you needed a separate package Eloquent Eager Limit by Jonas Staudenmeir.
See the pull request on GitHub:Â [11.x] Support eager loading with limit.
9. Casts Method
From Laravel 11, the casts will be provided in the protected method casts()
 instead of the protected property $casts
.
class User extends Authenticatable{// …protectedfunctioncasts():array{return [’email_verified_at’=>’datetime’,‘password’=>’hashed’,];}}
Also, now it is possible to provide an array.
protected function casts(): array{return [‘bookOptions’=> [AsCollection::class, OptionCollection::class],];}
This is a non-breaking change. You only need to know that the casts()
 method is prioritized over the $casts
 property.
See the pull request on GitHub:Â [11.x] Adds Model::casts() method and named static methods for built-in casters.
10. once() Method
There’s a new memoization function called once()
. This function ensures that a callable is called only once, returning the same result on subsequent calls.
class User extends Model{publicfunctionstats():array{returnonce(function(){// Expensive operations to generate user stats, multiple db queries, etc…return$stats;});}}
// Assuming you have two User instances: $userA and $userB
$userA->stats();
$userA->stats(); // cached result from previous line…
$userB->stats(); // Not using $userA cached results, because $userB !== $userA
$userB->stats(); // cached result from previous line…
See the pull request on GitHub:Â [11.x] Adds once memoization function.
11. New Welcome Page
Laravel 11 comes with a new welcome page. The images below show how it looks in light and dark mode.
See More: HTTP status codes
Your blog post had me hooked from the very beginning!