Laravel 11, which had been greatly anticipated, was released on March 12, 2024, causing excitement in the PHP developer community. This major edition demonstrates Laravel’s dedication to continual improvement by delivering various new features and updates that expedite development workflows and enable developers to create more powerful and scalable web projects.
Table of Contents
Real-Time Communication with Laravel Reverb
Laravel 11 features Laravel Reverb, a first-party, scalable WebSocket server. This allows developers to create real-time features such as chat applications, collaborative editing tools, and live dashboards directly within the Laravel environment.
- Incredibly fast: Reverb is optimized for speed. A single server can handle thousands of connections and data transfers without the delay and inefficiency of HTTP polling.
- Seamless Integration: Utilize Laravel’s broadcasting features. Deploy using Reverb’s first-party Laravel Forge integration. Monitor with built-in pulse support.
- Built to scale: Increase capacity indefinitely by employing Reverb’s built-in support for horizontal scalability with Redis, which allows you to manage connections and channels across several servers.
- Pusher: Reverb uses the Pusher protocol for WebSockets, so it’s immediately compatible with Laravel Broadcasting and Laravel Echo.
A Streamlined Application Structure
- Credit: LaraPhant
- Original Video Link: https://youtu.be/uK1G0_-7DWY
Laravel 11 features a more ordered application structure, which is a significant upgrade. While current applications are not obliged to use this framework, it does provide a lighter and more modern approach to project management. Here is a breakdown of the major changes.
1. Removed Http/Kernel
The Http/Kernel.php
file has been removed, and Bootstrap/App now allows you to do most of what you could do in the kernel.
return Application::configure()
->withProviders ()
-›withRouting(
web: __DIR__.'/../routes/web.php'
commands: __DIR__.'/../routes/console.php',
)
->withMiddleware(function(Middleware Smiddleware) {
$middleware->web(append: LaraconMiddleware::class):
})
PHP2. Model Casts Revamp
- Credit: Laracasts
- Original Video Link: https://youtu.be/KXEl__vPo5M
Model casts are now defined as methods rather than properties. When specified as a method, we can perform further operations, such as calling other methods directly from casting. Here’s an example with the new Laravel 11 AsEnumCollection
.
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'options'=› AsEnumCollection::of(UserOption::class),
];
}
PHP3. New Dumpable Trait
The dumpable trait enables developers to easily export objects and relationships for debugging. This improves the troubleshooting experience.
class Stringable implements JsonSerializable, ArrayAccess
{
use Conditionable, Dumpable, Macroable, Tappable;
str('foo')->dd();
str('foo')->dump();
PHP4. Config Changes
Configuration files have been rearranged for easier maintenance. Namespaces are now utilized to organize configuration options, making it easier to find and manage them.
// config/app.php
<?php
return [
'timezone' => 'America/Kentucky/Louisville',
'custom_option' => 'foo'
];
PHP5. New Once Method
- Credit: Laratips
- Original Video Link: https://youtu.be/1Lhc-OA-zWg
The once method allows you to ensure that a certain closure is only invoked once per application request. This is handy for actions that should only be performed at the start of a request cycle.
6. Slimmed Default Migrations
The default migration structure has been simplified, focusing on the fundamental functionality of creating and changing database tables. This removes boilerplate code, resulting in simpler migrations.
Enhanced Developer Experience
1. Routes Updates
Route declarations now include better type hinting and support for named arguments. This increases code readability and maintainability. By default, there will only be two route files: console.php and web.php. API routes are now opt-in using php artisan install:api
, which returns the API routes file and Laravel Sanctum.
The same goes for websocket broadcasting (php artisan install:broadcasting
).
2. New Up Health Route
- Credit: Laravel News
- Original Video Link: https://youtu.be/EmvHPg8JpB4
A new /up health route has been added to provide a quick way to determine whether the application is running and healthy. This is useful for monitoring and integrating data.
3. APP_KEY Rotation
Laravel 11 adds a more gentle way to rotate the application’s encryption key. This ensures a more efficient and secure key management method.
4. Console Kernel Removed
The console kernel has been eliminated, which simplifies the Artisan command execution process. Commands are now entered directly into the app/Console/Commands
directory.
Security and Performance Focus
Laravel’s focus is on security and performance. Laravel 11 introduces:
1. Per-Second Rate Limiting
Enhanced rate restriction enables developers to set rate limits on a per-second basis, allowing for more precise control over API access and preventing misuse.
2. Eager Load Limit
- Credit: Laracasts
- Original Video Link: https://youtu.be/SfFA2dVHlsU
To improve efficiency, the eager loading of relationships in Eloquent models now has a configurable limit that prevents unnecessary database requests.
User::select('id', 'name')->with([
'articles' => fn($query) => $query->limit(5)
])->get();
PHPImproved Testing and Debugging
Laravel 11 improves its testing and debugging capabilities:
- Queue Testing Enhancements: Testing queued jobs has been more efficient, with improved support for mocking and asserting job behavior.
- Resend Mail Transport: The new Resend Mail Transport enables developers to simply resend previously sent emails for testing and debugging.
- Prompt Validator Integration: The Prompt validation library has been fully merged with Laravel’s validation system, providing a more user-friendly approach to design and execute validation rules.
New Artisan Commands
Several new Artisan commands have been added to streamline development tasks:
php artisan make:class
php artisan make:enum
php artisan make:interface
php artisan make:trait
BashUpgrading to Laravel 11
The Laravel team knows the value of smooth transitions. While Laravel 11 includes some breaking changes, the upgrade process is intended to be simple. The official documentation provides extensive upgrading recommendations to help developers convert their current apps to Laravel 11 with minimal effort https://laravel.com/docs/11.x/upgrade.
Laravel Support Policy
Version | PHP (*) | Release | Bug Fixes Until | Security Fixes Until |
---|---|---|---|---|
Laravel 9 | 8.0 – 8.2 | February 8th, 2022 | August 8th, 2023 | February 6th, 2024 |
Laravel 10 | 8.1 – 8.3 | February 14th, 2023 | August 6th, 2024 | February 4th, 2025 |
Laravel 11 | 8.2 – 8.3 | March 12th, 2024 | September 3rd, 2025 | March 12th, 2026 |
12 | 8.2 – 8.3 | Q1 2025 | Q3, 2026 | Q1, 2027 |
Conclusion
The official release of Laravel 11 is a big milestone in web development. Its streamlined structure, improved developer experience, real-time communication capabilities, and enhanced security features allow developers to create modern, resilient, and scalable online applications.
This blog post provides critical information about the basic features and functionality of Laravel 11. Whether you’ve used Laravel before or are new to web development, Laravel 11 provides a framework for effectively bringing your ideas to life.
FAQ
Laravel 11 adds native WebSocket support, improved authentication with MFA, performance enhancements, a new queueing mechanism, and updated Blade components.
Follow the official upgrading guide provided by the Laravel documentation, updating dependencies and replacing or removing deprecated code.
Yes, Laravel 11 features several performance improvements for database queries, caching, routing, and framework execution.
While Laravel attempts for backward compatibility, big releases such as version 11 may include breaking changes or deprecations. Specific information can be found in the release notes and upgrading guides.
The Laravel website provides detailed documentation for Laravel 11, as well as community forums, tutorials, and online tools for extra help.