Table of Contents
Introduction
Laravel is a top PHP framework used for making websites. It's known for being easy to use, following a clear structure, and having many helpful guides. When developers want to make strong websites quickly, they often choose Laravel.
Laravel is the best option for web developers across the globe as it provides them with endless tools and features. There is a general wait for version 11, which is outlined to be released soon. People are eager to see what is ahead and how it might impact the community.
Now’s your time to start discovering all the cool stuff that Laravel will be able to offer you with its version 11 update. Let’s jump in and have a look at it.
When will the New Laravel 11 Release?
Laravel 11 will be launched on February 6th this year, and developers seem to be going fanatical about the same. As with the previous updates, this new release of a famous PHP framework will offer plenty of great novelties and improvements. Laravel keeps getting better every time it is updated, which makes this tool an excellent choice to create websites. The hype relating to Laravel 11 underscores the significance of this web programming for contemporary website applications.
A look at the new features and updates in laravel 11
Here’s a look at some major changes you will find with Laravel 11:
-
PHP 8.1 will not get any Support!
Laravel 11 is bringing a significant change by not supporting PHP 8. This is because by the time Laravel 11 is established, PHP 8.2 will be fully set in stone, and PHP 8.3 will have gained stability too. With two newer versions available, sticking to the older PHP 8.1 doesn't make sense. Switching to the latest version right away is optional, but it's a good idea to test things out thoroughly. You can update your existing apps step by step, but going for the latest version is smart.
-
Config Simplified
In Laravel 11, there's a change with config files. They've been removed, and all config settings flow down from one place. The .env file has been made bigger to include all your settings.
There's also a new command called config:publish, which lets you return any config settings you want. But even if you bring them back, you can still eliminate any settings you don't want to change using the new cascade feature. For instance, running ‘artisan config:publish database‘ creates a specialized database configuration file, making precision and organization a breeze like this:
// To publish all config files php artisan config:publish // For a specific config file php artisan config:publish database
-
Slimmer Skeleton
In Laravel 11, the app skeleton is now slimmer, which helps developers work faster by cutting down on repetitive code. Here are some of the main changes you'll find:
- You won't see '$policies' in 'AuthServiceProvider' anymore because the framework will find them independently.
- You don't need 'SendEmailVerificationNotification' because 'EventServiceProvider' covers the basics, including auto-event discovery.
- 'RedirectIfAuthenticated' is simpler now thanks to changes in the framework's internal workings.
- Thanks to removing the 'Authenticate' middleware call for JSON routes, unnecessary ternary checks are gone.
- Custom Artisan is now automatically loaded, so you no longer have to use the 'load()' method.
-
The All New Dumpable Trait
In Laravel 11, there's a cool new thing – the Dumpable trait. It lets you use dd() and dump() with your objects. This change is part of a pull request that introduces the Dumpable trait, meant to take over the current dd and dump methods in most of the framework's classes.
This trait makes it easy for both regular users and folks making packages for Laravel to add debugging methods to their classes.
Here's an example of code demonstrating how it's used:
namespace App\ValueObjects; use Illuminate\Support\Traits\Dumpable; use Illuminate\Support\Traits\Conditionable; class Address { use Conditionable, Dumpable; // ... } $address = new Address; // Before: $address->foo()->bar(); // After: $address->foo()->dd()->bar();
-
Changes in Model Cast
In Laravel 11, there are some changes with model casts. Instead of being a property, they're now defined as a method. This lets us do more things, like calling other methods directly from the casts. In Laravel, you typically set attribute casting in an Eloquent model like this:
class User extends Model { protected $casts = [ 'email_verified_at' => 'datetime', ]; }
With Laravel 11, there's a new way to define casting using a casts() method in your model. This allows you to use static methods with parameters. Here's how it's done:
class User extends Model { protected function casts() : array { return [ 'foo' => AsCollection::using(FooCollection::class), ]; } }
Additionally, you can now specify your casts as an array.
-
#New Artisan Commands
New Artisan commands have been added to allow the quick creation of classes, enums, interfaces, and traits:
php artisan make:class php artisan make:enum php artisan make:interface php artisan make:trait
-
Routes Changes
There's also a change in routes. Now, there will be two route files: web.php and console.php. If developers want API routes, they can use the command
'php artisan install: API'
to get the API routes file and Laravel Sanctum. And if they need websocket broadcasting, they can use'php artisan install: broadcasting'
. -
Compressed Default Migration
In Laravel v11, there's a change with the default migrations. Instead of having them spread out in many files, the migrations from 2014 and 2019 will now be put into just two files. This makes the database/migrations directory cleaner and easier to manage for developers starting a new Laravel project.
-
Removal of Console Kernel
Another important change is with the Console Kernel. It's gone now, just like the HTTP Kernel. Instead, developers will put their console commands directly into the routes/console.php file. This file used to have Artisan commands as closures, but now it's the main place for registering all console commands.
Conclusion
Laravel 11, set to release on February 6th, 2024, promises exciting enhancements and support. From simplified configuration to a slimmer skeleton, it's poised to streamline development and empower creators.