What’s New in Laravel 11: New Features and Latest Updates
Today, in this tutorial I would like to share with you the new upcoming laravel 11 version features with you. I will show you major new features and new updates about laravel 11.
Laravel 11 release date is 12th March 2024.
Laravel team releases new versions every year in February. They release a new version with so many new features so developers can easily use it and make it a more professional and smooth web application.
In this post, I will show you what new updates made in the laravel 11 version. So, let's see one by one:
Laravel 11 Release Date
The latest information on Laravel’s official website, according to the Support Policy, indicates that Laravel 11 is scheduled to release its latest version on February 6, 2024. It is worth noting that Laravel’s core team adheres to the Semantic Versioning methodology, which means major updates to the framework are typically launched annually during the first quarter.
Now, let's see the new updates and features of Laravel 11.
No Support For PHP 8.1 in Laravel 11
Laravel version 11 brings a notable change by no longer supporting PHP 8.1. This decision is grounded in the anticipation that, upon the release of Laravel 11, PHP 8.2 will have attained complete stability, with PHP 8.3 also reaching a stable state.
So, If you want to use Laravel 11 then you need to install PHP 8.2 or PHP 8.3 version.
Laravel 11 will More Minimalistic Application Skeleton
In Laravel 11, an optimized application structure has been implemented to minimize the presence of redundant code, benefitting both business owners and developers. This enhancement leads to more efficient development processes.
When you install Laravel 11, you will be greeted by an ultra-minimalistic application skeleton that looks 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
You can see the list of following changes made:
- In the AuthServiceProvider the framework automatically discovers and removes the $policies.
The inclusion of SendEmailVerificationNotification in the EventServiceProvider is no longer necessary, as it is now automatically registered by the base EventServiceProvider. Furthermore, it's worth noting that Laravel now defaults to enabling auto-event discovery.
The BroadcastServiceProvider is no longer essential, leading to its removal. Consequently, the framework no longer automatically loads the routes/channels.php file.
- Improving RedirectIfAuthenticated is facilitated by the framework’s core functionality.
- The Authenticate middleware no longer invokes the redirectTo() method for JSON routes, eliminating the need for redundant ternary checks.
- We removed the EncryptCookies, PreventRequestsDuringMaintenance.php, TrimStrings, TrustHosts, TrustProxies, ValidateCsrfToken and ValidateSignature middleware from the skeleton structure.
- In Laravel 11, it's now easier because the Custom Artisan function is already part of it. You don't have to manually use the load() method in the console anymore.
- Deleting the routes/console.php file is a big deal. Now, you just need to put your special commands directly in the console kernel.
- The AuthorizesRequests and ValidatesRequests traits have been eliminated from the foundational controller.
- The bootstrap/app.php file has been streamlined, currently containing just three lines of code.
- Laravel version 11 has removed the exception handler.
Laravel 11 Add Dumpable Trait(dump() and dd() with Objects)
Laravel 11 added new Dumpable Trait and you can easily dump your objects. Specially, it will help you to debug your laravel eloquent query builder and you can debug relational database as well.
So, let's see the simple 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 define your casting through a casts() method in your model, giving you a chance to use static methods from the class doing the casting. This is how it looks:
I will show old one and new one with the bellow code:
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
In Laravel 11, they removed config file by defaults and they also added some more variable on .env file so, you can configure it from .env file. But if you want to back all config file then you need to run following command:
Publish All Config File:
php artisan config:publish
Publish Specific Config File:
php artisan config: publish database
Laravel 11 Slimmed Default Migrations Names
Laravel 11 will have new migrations names. before it was showing creation date with migration name but in new version it will add properly new naming with as i show you in the bellow example:
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
Laravel 11 removed console kernel file. now you don't have to register your console command with kernel file. You can declare it as like the bellow:
php artisan make:command TestCommand
// Console command [app/Console/Commands/TestCommand.php] created successfully.
routes/console.php
Schedule::command('app:test-command')->hourly();
That's it.
Laravel 11 added more changes but i share with you some of it.
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Convert Number to Words in Laravel?
- How to Call a Controller Function in Another Controller in Laravel?
- How to Setup File Permissions Correctly in Laravel?
- Laravel Google Maps Multiple Markers Example
- How to Install Laravel in Ubuntu Server?
- How to Remove Composer Package in Laravel?
- Deploy Laravel Vapor Project with Docker Tutorial
- How to Run Migration and Seeder on Laravel Vapor?
- How to Image Upload in Laravel Vapor?
- How to Setup Database in Laravel Vapor?
- How to Deploy Project with Laravel Vapor?
- How to Restore Deleted Records in Laravel?
- How to Create Custom Log File in Laravel?
- How to Send Mail using Mailjet in Laravel?