I’d like to go over the new, upcoming Laravel 11 new features of the edition with you in this tutorial today. I’ll walk you through the main enhancements and new features of Laravel 11.
The release date of Laravel 11 is March 12, 2024.
New versions are always released every February by the Laravel team. To make it easier for developers to utilize and create a more polished and seamless online application, they release a new version that has a ton of new capabilities.
I’ll demonstrate the latest updates included in the Laravel 11 version in this post. Let’s examine each one individually now:
Laravel 11 Release Date
According to the Support Policy, the most recent information available on Laravel’s official website states that the most recent version of Laravel 11, Laravel 11, is expected to be released on February 6, 2024. Notably, the core Laravel team follows the Semantic Versioning technique, meaning that significant framework upgrades are usually released in the first quarter of each year.
Let’s now examine Laravel 11’s latest features and changes.
No Support For PHP 8.1 in Laravel 11
One significant change in Laravel version 11 is the removal of support for PHP 8.1. This choice is based on the expectation that PHP 8.2 will be fully stable by the time Laravel 11 is released, and that PHP 8.3 will likewise be stable by then.
Thus, you must install PHP 8.2 or PHP 8.3 if you wish to run Laravel 11.
Laravel 11 will More Minimalistic Application Skeleton
Laravel 11 offers developers and company owners alike the advantage of less redundancy in code thanks to an optimized application structure. Development procedures become more effective as a result of this improvement.
The ultra-minimalistic application skeleton that greets you upon installing Laravel 11 looks something like this:
app
|--- Http
| |--- Controllers
| |--- Controller.php
|--- Models
| |--- User.php
|--- Providers
| |--- AppServiceProvider.php
bootstrap
|--- app.php
|--- cache
| |--- packages.php
| |--- services.php
|--- providers.php
routes
|--- console.php
|--- web.php
The list of the following modifications is visible to you:
- The framework finds and eliminates the $policies automatically in the AuthServiceProvider.
- SendEmailVerificationNotification is now automatically registered by the main EventServiceProvider, therefore the inclusion of this in the EventServiceProvider is no longer required. It’s also important to note that auto-event discovery is now enabled by default in Laravel.
- Since the BroadcastServiceProvider is no longer needed, it has been removed. As a result, the routes/channels.php file is no longer automatically loaded by the framework.
- The fundamental features of the framework assist the improvement of RedirectIfAuthenticated.
- Repetitive ternary tests are no longer necessary because the Authenticate middleware no longer calls the redirectTo() method for JSON routes.
- The middleware for ValidateCsrfToken, ValidateSignature, TrimStrings, TrustHosts, TrustProxies, EncryptCookies, and PreventRequestsDuringMaintenance.php were eliminated from the skeletal structure.
- Because the Custom Artisan function is already included in Laravel 11, it is now simpler. It is no longer necessary to manually use the console’s load() method.
- It is important to remove the routes/console.php file. All you have to do now is insert your unique commands into the console kernel directly.
- In the fundamental controller, the AuthorizesRequests and ValidatesRequests traits have been removed.
- There are now only three lines of code in the redesigned bootstrap/app.php file.
- The exception handler has been deleted in Laravel version 11.
Add Dumpable Trait (dd() and dump() with Objects) in Laravel 11
Dumpable is a new trait added to Laravel 11 that makes it simple to dump things. In particular, it will assist you in debugging both relational databases and the Eloquent query builder in Laravel.
Now let’s look at the fundamental example code:
<?php
namespace App\ValueObjects;
use Illuminate\Support\Traits\Dumpable;
use Illuminate\Support\Traits\Conditionable;
class Student
{
use Conditionable, Dumpable;
/* ... */
}
$student = new Student;
// Before:
$student->foo()->bar();
// After:
$student->foo()->dd()->bar();
Model::casts() Method Live in Laravel 11
With Laravel 11, you can now use static methods from the class that does the casting by defining your casting through a casts() function in your model. This is how it appears:
I’ll display both the old and new one using the code below:
namespace App\Models;
use App\Enums\UserRole;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/* OLD method */
protected $casts = [
'role' => UserRole::class,
];
/* NEW Method */
protected function casts() : array
{
return [
'role' => UserRole::class,
];
}
}
Laravel 11 Removed Config Files By Default
Laravel 11 eliminated the config file by default and added additional variables to the.env file so that you could configure it there. However, you must execute the following command if you wish to backup every configuration file:
Publish All Config File:
php artisan config:publish
Publish Specific Config File:
php artisan config: publish database
Laravel 11 Slimmed Default Migrations Names
There will be new migration names in Laravel 11. Previously, it displayed the creation date along with the migration name; however, the latest version will appropriately add new naming, as I’ve demonstrated in the sample below:
OLD Migrations Name:
migrations
|---2014_10_12_000000_create_users_table.php
|---2014_10_12_100000_create_password_reset_tokens_table.php
|---2019_08_19_000000_create_failed_jobs_table.php
NEW Migrations Name:
migrations
|---0001_01_01_000000_create_users_table.php
|---0001_01_01_000001_create_jobs_table.php
Laravel 11 Removed Console Kernel
Console kernel file was removed in Laravel 11. Your console command no longer needs to be registered with the kernel file. You can describe it as follows:
php artisan make:command TestCommand
// Console command [app/Console/Commands/TestCommand.php] created successfully.
routes/console.php
Schedule::command('app:test-command')->hourly();
And that’s it.
I’ll share a few of the other changes made by Laravel 11 with you.
I hope it’s useful to you.