Laravel 11, released on March 12, 2024, is a significant update to the Laravel framework, introducing various new features and improvements aimed at improving the development experience and application performance. Laravel 11 brings several important enhancements with a focus on efficiency, security, and real-time web application development, and introduces Laravel Reverb, a new WebSocket server for real-time communications.
Laravel Support Policy
Laravel’s support policy ensures that developers receive timely updates, bug fixes, and security patches for their applications. According to this policy, Laravel provides 18 months of bug fix support and 2 years of security fix support with each major release. This structured approach to version support allows developers to effectively plan their upgrade paths and keep their applications secure and up-to-date.
version | Supported PHP | release date | Until bug fix | Security fix deadline |
---|---|---|---|---|
Lalabel 9* | 8.0 β 8.2 | February 8, 2022 | August 8, 2023 | February 6, 2024 |
Lalabel 10 | 8.1 β 8.3 | February 14, 2023 | August 6, 2024 | February 4, 2025 |
Lalabel 11 | 8.2 β 8.3 | March 12, 2024 | September 3, 2025 | March 12, 2026 |
Lalabel 12 | 8.2+ | Q1 2025 | Q3 2026 | Q1 2027 |
Laravel 9 has reached end of support
PHP 8.2 requirements for Laravel 11
With the release of Laravel 11, PHP version requirements have changed significantly. Laravel 11 requires PHP 8.2 as a minimum version, aligning the framework with the latest features, performance improvements, and security enhancements provided by PHP 8.2. This decision underscores Laravel’s commitment to leveraging the latest and most robust technology available to ensure developers can build efficient, secure, and innovative applications.
PHP 8.2 introduces a number of new features and optimizations that will greatly benefit your Laravel applications. These include object-oriented programming enhancements, new types and attributes to improve your coding practice, and performance improvements that help your applications run faster. By requiring PHP 8.2, Laravel ensures that all applications built with this version inherently take advantage of these improvements, resulting in more reliable and performant web solutions.
Developers planning to upgrade to Laravel 11 or start new projects using Laravel 11 should ensure their server environment is updated to PHP 8.2. In addition to promoting compatibility with Laravel 11, this update allows applications to benefit from active support for PHP, including security fixes and performance optimizations.
Streamlined directory structure Kernel.php
Laravel 11 simplifies the directory structure, reducing initial complexity for developers. especially, bootstrap/app.php
The file has been removed and you can now add middleware directly.
<?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();
app.php config
of
config/broadcasting.php
config/cors.php
config/hashing.php
config/sanctum.php
config/view.php
The directory has been slimmed down by removing some of the files that were previously included in Laravel 10, such as: routes
of
routes/api.php
routes/channel.php
routes/console.php
The directory was also cleaned up a bit by removing:
eager load shedding
class User extends Model
{
public function posts()
{
return $this->hasMany(Post::class);
}
}
class Post extends Model
{
// ...
}
$users = User::with(['posts' => function ($query) {
$query->latest()->limit(10);
}])->get();
The introduction of aggressive load shedding allows developers to efficiently query relevant models without overloading the system with unnecessary data. This feature improves application performance by optimizing the data loading process and limiting the number of related records that are loaded. In previous versions of Laravel, you had to install a separate package for aggressive load shedding.
Modeling casts as methods
use App\Enums\UserOption;
use Illuminate\Database\Eloquent\Casts\AsEnumCollection;
// ...
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'options' => AsEnumCollection::of(UserOption::class),
];
}
Laravel 11 allows you to define casts as methods within your model classes, giving you more flexibility in how you cast data when retrieving from or saving data to the database. This method-based approach provides a clearer and more dynamic way to handle data casts, making the overall code more readable and maintainable. $cast
For comparison, in Laravel 10 this model cast is defined using:
protected $casts = [
'options' => AsEnumCollection::class.':'.UserOption::class,
];
You can use array properties, but you cannot call static methods.
Laravel Reverb: Real-time communication
Laravel Reverb stands out as one of the most exciting additions to Laravel 11, providing a first-party WebSocket server that facilitates real-time communication between client and server. Reverb is designed for high performance and can support thousands of connections simultaneously without the inefficiencies of HTTP polling. It integrates seamlessly with Laravel’s existing broadcast capabilities and is built for scalability with support for horizontal scaling using Redis. This makes it a robust solution for developers looking to incorporate real-time functionality into their applications, such as live chat, notifications, and dynamic content updates.
Reverb is optimized for speed, integrates smoothly with Laravel Forge for deployment, and offers built-in monitoring support with Pulse. The Pusher protocol ensures compatibility with Laravel Broadcast and Laravel Echo, making it easy to develop engaging and interactive web applications.
Actual implementation and scaling
Implementing Laravel Reverb involves installing packages, configuring them according to your project requirements, and integrating optimizations to enhance your application. Testing and validating these integrations is important to ensure that real-time functionality works as expected. We also recommend that you monitor application performance after deployment to identify and address potential bottlenecks.
New Artisan Commands
New Artisan commands in Laravel 11 improve developer productivity and significantly reduce the boilerplate code required when adding new components to your application. With commands to generate classes, enums, interfaces, and traits, developers can now scaffold new parts of their applications with minimal effort. These commands are designed to streamline the development process, allowing you to quickly set up and build application logic and data representations. These commands help developers adhere to best practices for code organization and maintainability and keep their codebases clean and well-structured. php artisan make:enum
for example, php artisan make:interface
Creating enums is simplified and helps define a set of named constants. Enums make your code more readable and less error-prone by restricting the values ββthat variables can have. Similarly, php artisan make:trait
and
Commands facilitate the adoption of SOLID principles by promoting the use of interfaces to define contracts within applications and traits to share methods between classes.
Health roots and APP_KEY rotation /up
of
Health routes and APP_KEY rotation features are important for maintaining the security and reliability of your Laravel application. Health routes are very useful for monitoring uptime and alerting systems because they provide an easy way to verify that your application is running and responding. By integrating this route, developers can easily set up health checks to monitor the status of their applications, allowing them to quickly detect and respond to downtime. APP_KEY
The APP_KEY rotation feature addresses common security concerns by allowing you to safely rotate your application’s encryption keys without risking data loss. In previous versions of Laravel, APP_PREVIOUS_KEYS
Encryption dependencies on this key can make your data inaccessible. Laravel 11 introduces a more flexible approach, allowing older data to
Use environment variables when encrypting new data with the current key. This feature maintains high security standards, as regularly rotating keys can protect against certain types of cryptographic attacks without the drawback of losing access to encrypted data. essential for.
Install Laravel11
If you’re setting up a new Laravel 11 installation, just follow the normal steps for installing Laravel manually or via Softaculous.
How to upgrade to Laravel 11
There are two routes to upgrading to Laravel 11. You can upgrade manually by following Laravel’s upgrade guide, or you can pay for Laravel Shift to automate the upgrade process.
conclusion
These enhancements in Laravel 11 highlight the framework’s commitment to promoting efficient development practices while ensuring application security and resiliency. By incorporating these features, Laravel continues to provide a robust foundation for building and maintaining modern PHP applications, meeting the evolving needs of developers and the industry at large.
check mark check mark check mark check mark
developer tools
Laravel hosting
related