Top 10 Things to Know About Laravel 11

Laravel 11, the highly anticipated update to one of the most popular PHP web development frameworks, is on the horizon, with a scheduled release in Q1 of 2024. Although the official release date is still a few months away, Laravel's creator, Taylor Otwell, has offered a tantalizing glimpse of what's in store during his keynote address at Laracon.

In this article, we'll delve into some of the exciting new features and substantial improvements that are set to transform the Laravel ecosystem with the upcoming release. While these details are based on the insights shared so far, keep in mind that the final feature set may evolve as development progresses

Streamlined Directory Structure

Laravel 11 is getting some changes to how things are organized. One big change is how we handle controllers, which are parts of the code that control what happens when you visit a webpage.

In older versions, controllers had a default setup that developers had to follow. But in Laravel 11, that's changing. Now, controllers won't have any default setup. This means developers have more freedom to organize their code the way they want. It's like giving them a blank canvas to work with.

Middleware is a way to add extra functions to your web application, like security checks or logging. In the past, Laravel had a dedicated folder for middleware. But in Laravel 11, that folder is going away.

Instead, developers can customize middleware in a simpler place, called App/ServiceProvider. It's like moving your tools to a more convenient toolbox. This change makes it easier to control how your web app works by keeping things neat and tidy.

In a nutshell, Laravel 11 is making it easier for developers to build web applications their way and manage extra features like middleware in a more straightforward manner.

public function boot(): void
{
    EncryptCookies::except(['some_cookie']);
}

 

No more Http/Kernel in Laravel 11

In Laravel 11, there's a change in how the framework handles certain tasks that used to be done in something called the Http/Kernel. This Http/Kernel was like the control center for managing different parts of a web application.

But now, in Laravel 11, many of the things you used to do in the Http/Kernel have moved to a different place called Bootstrap/App. It's like a new control center for your web application.

This change makes things simpler and more organized. It's like rearranging your tools in a toolbox to find them more easily. So, instead of going to the Http/Kernel, you'll now find similar tasks in the Bootstrap/App, making it easier to control how your web application works.

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

 

Changes to Model Casts in Laravel 11

In Laravel 11, there's an important change in how we use something called "model casts." Model casts are like magic spells that transform data in your application.

Previously, we defined these model casts as properties, but in Laravel 11, we're doing it a bit differently. Now, we define them as methods, which is like a set of instructions on how to cast data. This method approach gives us more flexibility.

For example, in Laravel 11, we have something new called "AsEnumCollection." This allows us to transform data into an Enum Collection, which is like a special list of choices.

To give you a quick idea, here's an example of how you might use the new Laravel 11 AsEnumCollection.

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

 

 

Configuration Changes in Laravel 11

In Laravel, configuration files are like the settings for your application. They control how everything works. In previous versions, Laravel had a bunch of these config files spread around. But in Laravel 11, things are getting more streamlined and flexible.

1. No More Separate Config Files

Laravel 11 removes many separate config files, making things simpler. Instead of having lots of individual config files, all the configuration options now cascade down.

2. Expanded .env File

The .env file, which is where you set environment variables, gets a makeover. Now, it includes all the options you'd want to set for your application. This makes it easier to manage your app's settings from one central place.

3. Bring Back Config with config:publish

Laravel 11 introduces a new command called config:publish. This command lets you bring back any configuration you might want to customize. Even if some config options are no longer in separate files, you can still retrieve and adjust them using this command.

4. Customize with Ease

With the new cascade feature, you can easily customize your application's configuration. You can remove any options you don't want to change, and only focus on the ones that matter to you. This flexibility makes it simpler to configure Laravel 11 to match your project's unique needs.

 

Slimmed Default Migrations in Laravel 11

When you begin a new Laravel application, it comes with some default migrations. Migrations are like blueprints for your database, specifying how it should be structured.

In earlier versions of Laravel, these default migrations were spread across different files, some dating back to 2014 and 2019. But in Laravel 11, things are getting more organized and streamlined.

1. Dates Removed

In Laravel 11, the default migrations no longer include dates. This means the years 2014 and 2019, which were part of the migration filenames, have been removed. So, instead of having migrations like "2014_10_12_create_users_table.php" and "2019_08_04_create_posts_table.php," you'll have simpler filenames.

2. Consolidated into Two Files

These default migrations have been condensed and merged into just two files. This consolidation makes it cleaner and easier to manage your database structure when you start a new Laravel application.

So, when you create a new Laravel app with Laravel 11, you won't see those long, dated migration filenames anymore. Instead, you'll have just two files that contain all the necessary instructions for setting up your database tables.

 

Route Changes in Laravel 11

In Laravel, routes are like the map that tells your application how to respond to different requests. In previous versions, Laravel provided several route files by default. But in Laravel 11, things are becoming more modular and focused on what you need.

1. Simplified Default Route Files

By default, Laravel 11 simplifies the route structure. Instead of multiple route files, you'll have only two:

  • console.php: This file handles routes related to command-line tools and tasks.
  • web.php: This file manages routes for your web application.

This streamlined structure makes it clearer and more organized, allowing you to focus on the routes that matter to your specific application.

2. Optional API Routes

API routes, which are used for building web services, are now optional. To enable them, you can use the php artisan install:api command. Running this command not only creates an API routes file but also sets up Laravel Sanctum, which is a package for API authentication.

This means that you have the flexibility to decide whether your application needs API routes, and you can add them when required. It's like having an extra toolkit that you can choose to use when building API features.

3. WebSocket Broadcasting

Similar to API routes, WebSocket broadcasting is also opt-in. You can activate it using the php artisan install:broadcasting command. This command sets up the necessary configurations and tools for real-time broadcasting in your application.

 

 

Removal of Console Kernel in Laravel 11

In Laravel, the Console Kernel used to be a central place where you defined console commands for tasks like running scripts and managing your application from the command line. However, in Laravel 11, things are becoming more straightforward and user-friendly.

1. Console Commands in routes/console.php

In Laravel 11, you no longer need the Console Kernel to define your console commands. Instead, you can directly specify your console commands in the routes/console.php file. This file becomes the new home for your command definitions.

This change makes it easier to find and manage your console commands. It's like moving your tools from a toolbox to a more accessible drawer, so you can quickly access and organize your commands.

Now, when you want to create or manage console commands, you'll go straight to the routes/console.php file, where you can define and organize them according to your application's needs.

 

Minimum PHP 8.2 Requirement in Laravel 11

In Laravel 11, there's an important change regarding the version of PHP that your application needs to run. PHP is the programming language that powers your Laravel web applications.

1. PHP 8.2 Minimum Requirement

Laravel 11 apps now require a minimum version of PHP 8.2. This means that if you want to use or upgrade to Laravel 11, your server or hosting environment must have PHP 8.2 or a newer version installed.

2. Time to Upgrade

If you're currently running an older version of PHP, this is a good opportunity to upgrade. Using a more recent PHP version not only ensures compatibility with Laravel 11 but also provides access to new features, improved performance, and enhanced security.

 

Laravel Support Policy

For all Laravel releases, bug fixes are provided for 18 months and security fixes are provided for 2 years. For all additional libraries, including Lumen, only the latest major release receives bug fixes.

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.2 Q1 2023 August 6th, 2024 February 4th, 2025
Laravel 11 8.2 Q1 2024 August 5th, 2025 February 3rd, 2026

 

Conclusion

As Laravel 11 progresses and more features are announced or modified, it's crucial to stay updated with the official Laravel documentation and release notes. Keeping your knowledge up to date ensures that you can make the most of the new features and improvements while developing with Laravel.

 


You might also like:

techsolutionstuff

Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of techsolutionstuff.com. Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.

RECOMMENDED POSTS

FEATURE POSTS