Laravel 11 Launched Key Features and Updates

Laravel 11 is out now! It requires at least PHP v8.2 and introduces the new Laravel Reverb package. The directory structure is also streamlined for better organization. Get ready to boost your development workflow with these exciting updates!

#Laravel Reverb!

Have you heard about the latest addition to the Laravel ecosystem? “Laravel Reverb is a brand-new WebSocket server made specifically for Laravel apps. It helps messages travel quickly between your computer and the server, so you can chat in real-time. Reverbs have cool features like…

Blazing Fast Performance:

One of the standout features of Reverb is its lightning-fast performance. Engineered for speed, Reverb can effortlessly handle thousands of connections, delivering data without the delays typically associated with HTTP polling. With Reverb, you can expect seamless real-time communication without sacrificing efficiency.

Seamless Integration with Laravel:

Reverb easily connects with Laravel’s broadcasting features, so you can make the most of Laravel when creating real-time apps. Whether you’re sending out updates or setting up push alerts, Reverb makes it all simpler, making development smoother.

Forge Integration for Easy Deployment:

Deploying your Laravel apps using Reverb is super easy, thanks to its direct integration with Laravel Forge. With just a few clicks, you can send your Reverb-powered app to your server and start giving real-time updates to your users.

Built-in Monitoring with Pulse Support:

Monitoring your Reverb-powered applications is made easy with built-in support for Pulse. Keep track of your server’s performance, monitor active connections, and troubleshoot issues effortlessly, all within the Laravel ecosystem.

With its impressive speed, seamless integration with Laravel, and convenient deployment options, Laravel Reverb is set to become an indispensable tool for developers building real-time applications with Laravel. Experience the future of real-time communication – try Laravel Reverb today!

Built for Scale:

With Laravel Reverb, you can effortlessly boost your application’s capacity to handle more traffic and data. How? Reverb comes with built-in support for horizontal scaling using Redis. This means you can spread the workload across multiple servers, managing connections and channels with ease. So, as your application grows, Reverb ensures it stays responsive and efficient, even during peak usage periods.

Pusher Protocol Compatibility:

When it comes to real-time communication, compatibility matters. That’s why Reverb utilizes the Pusher protocol for WebSockets. This makes Reverb seamlessly compatible with Laravel broadcasting and Laravel Echo, two powerful tools for enabling real-time updates in your applications. With Reverb, you can implement features like live chat, notifications, and dynamic content updates effortlessly, enhancing the user experience without any hassle.

#Streamlined Directory Structure:

On a new installation, we’ve noticed that the number of files has decreased by about 69 files. That’s great!

Take a look at our latest post about the entirely new directory structure in Laravel 11.

In this update:

  • Controllers don’t automatically extend anything anymore.
  • There’s no separate directory for middleware anymore.
  • Laravel now comes with nine middleware included. Most of them you probably won’t need to change. But if you do want to customize them, you can find them in the App/ServiceProvider directory. For instance:
public function boot(): void
{
 EncryptCookies::except([‘some_cookie’]);
}

 

#No More Http/Kernel

In Laravel 11, there’s no need to use the Http/Kernel for many tasks anymore. Now, you can do most of what you used to do in the Kernel directly in the Bootstrap/App.

Here’s a simple example:

return Application::configure()
 ->withProviders ()
 ->withRouting(
 web: __DIR__.'/../routes/web.php',
 commands: __DIR__.'/../routes/console.php'
 )
 ->withMiddleware(function($middleware) {
 $middleware->web(append: LaraconMiddleware::class);
 });

This code snippet demonstrates how you can configure your application directly without relying on the Http/Kernel. With Laravel 11, managing routes and middleware has become even more straightforward, allowing you to focus on building your application.

 

#Model Casts Changes

Now, in Laravel 11, model casts are set up using a method instead of just putting them as a property. This change allows us to do more things, such as directly calling other methods from the casts. Let me show you an example using the new AsEnumCollection: feature.

protected function casts(): array
{
 return [
 'email_verified_at' => 'datetime',
 'password' => 'hashed',
 'options' => AsEnumCollection::of(UserOption::class),
 ];
}

With this change, managing model casts becomes more dynamic and adaptable to your application’s needs.

 

#New Dumpable Trait

Introducing the Dumpable trait in Laravel 11! This trait is designed to streamline the core of the framework by consolidating “dd” or “dump” methods present in multiple classes. Additionally, you can now utilize the Dumpable trait in your own classes.

Here’s a simple example:

class Stringable implements JsonSerializable, ArrayAccess
{
 use Conditionable, Dumpable, Macroable, Tappable;

 str('foo')->dd();
 str('foo')->dump();
}

By incorporating the Dumpable trait, debugging becomes more efficient and consistent across your application. Whether you’re working with Laravel core classes or your custom classes, the Dumpable trait ensures smooth debugging with ease.

 

#Config Changes

In Laravel 11, there’s a simplification in how configuration works. Instead of having separate config files for various settings, all config options now cascade down. This means you can find everything you need in the .env file, which has been expanded to include all the options you might want to set. Check out more details about these config changes to understand how they affect your Laravel project.

#New Once Method

In Laravel 11, there’s a new ‘once’ helper method. It guarantees that no matter how many times you call a method on an object, you’ll always get the same value. This ‘once’ function comes in handy when you want to make sure that certain code runs only once.

#Slimmed Default Migrations

When you create a new Laravel app, it already has some default migrations from 2014 and 2019. Now, these migrations will be updated: the dates will be removed, and they’ll be combined into just two files.

#Routes Changes

Laravel 11 brings changes to how routes are handled by default. Now, there are only two route files: console.php and web.php. If you need API routes, you’ll have to opt-in by running the command “php artisan install:api,” which will provide you with the API routes file and Laravel Sanctum integration. Similarly, for websocket broadcasting, you can use the command “php artisan install:broadcasting” to enable this feature in your application. Keep up with these route changes to ensure your Laravel project stays up to date with the latest improvements.

#New Up Health Route

In Laravel 11, there will be a new ‘/up’ health route. It triggers a DiagnosingHealthEvent, which helps you integrate with uptime monitoring more effectively.

#APP_KEY Rotation

In older versions of Laravel, changing your APP_KEY could sometimes cause issues with encrypted data in the database.  But in Laravel 11, there’s a new feature called graceful rotation. This feature ensures that old encrypted data won’t break when you change the key. It does this by storing previous keys in an APP_PREVIOUS_KEYS variable in your .env file, separated by commas. Laravel will automatically re-encrypt the data using the new key.

#Console Kernel Removed

The Console Kernel is being removed. Instead, you’ll be able to define your console commands directly in the ‘routes/console.php’ file.

#Named Arguments

Laravel’s backward compatibility guidelines don’t include named arguments. This means that function arguments might be renamed in the Laravel codebase to make it better. So, when you use named arguments to call Laravel methods, be careful because the parameter names might change later on.

#Eager Load Limit

With Laravel 11, you get integrated support for the “eager load limit” feature. This allows you to limit the number of related records fetched when using eager loading. For example:

User::select('id', 'name')->with([
 'articles' => fn($query) => $query->limit(5)
])->get();

This code limits the number of articles fetched to five, optimizing performance and improving efficiency when working with related data.

 

#New Artisan Commands

In Laravel 11, we’re introducing some handy new Artisan commands. These commands make it quick and easy to create classes, enums, interfaces, and traits in your Laravel projects. Here they are:

  • To create a class: php artisan make:class
  • To create an enum: php artisan make:enum
  • To create an interface: php artisan make:interface
  • To create a trait: php artisan make:trait

#New Welcome Page

With the latest updates to Laravel, we’re also rolling out a fresh new welcome page. When you create a new Laravel application, you’ll be greeted with this revamped welcome page, providing a more welcoming and informative starting point for your project.

#When Will Laravel 11 Be Released?

Mark your calendars! Laravel 11 is set to be released on March 12, 2024. Get ready for the latest and greatest features and improvements in this exciting new release.

#PHP 8.2 Minimum Support

Heads up! Laravel 11 apps will require a minimum of PHP 8.2. If you’re currently using an older version of PHP, now’s a good time to consider upgrading to ensure compatibility with Laravel 11’s features and enhancements.

#SQLite 3.35.0+ Required

If you’re using a SQLite database with your Laravel application, please note that Laravel 11 will require SQLite version 3.35.0 or newer. Make sure your SQLite setup meets this requirement for smooth operation with Laravel 11.

#Doctrine DBAL Removal

In Laravel 11, we’ve bid farewell to the dependency on Doctrine DBAL. This means you no longer need to register custom Doctrine types for creating and altering various column types. Laravel now handles these tasks seamlessly without the need for custom types.

#Install Laravel 11

Ready to dive into Laravel 11? The easiest way to get started is by setting up the Laravel Installer first. Here’s how:

  • Install the Laravel Installer globally:
composer global require laravel/installer

Once installed, create a new Laravel project by running:

laravel new projectname

Enjoy exploring all the exciting new features of Laravel 11 in your projects!

 

#Upgrade to Laravel 11

If you’re looking to upgrade to Laravel 11, you have a couple of options. The easiest way is to use Laravel Shift, which automates the upgrade process for you. Alternatively, you can follow the upgrade guide provided in the Laravel documentation for a manual upgrade.

#Laravel Support Policy

Here’s a breakdown of the support policy for Laravel releases:

  • For each Laravel version, bug fixes are provided for 18 months, while security fixes are provided for 2 years.
  • Additional libraries, including Lumen, only receive bug fixes for the latest major release.
VersionPHP (*)Release DateBug Fixes UntilSecurity Fixes Until
Laravel 98.0 – 8.2February 8th, 2022August 8th, 2023February 6th, 2024
Laravel 108.1 – 8.3February 14th, 2023August 6th, 2024February 4th, 2025
Laravel 118.2 – 8.3March 12th, 2024September 3rd, 2025March 12th, 2026
Laravel 128.2 – 8.3Q1 2025Q3, 2026Q1, 2027


#Wrapping Up

All the features mentioned for Laravel 11 are currently in beta, aimed at enhancing your workflow. Keep in mind that things might change, and we’ll ensure to update this post as new features are announced.

 

x
X