Laravel

Introducing Laravel 11 New Released: The Next Evolution in Web Development

614 Views 11 March 2024
Introducing Laravel 11 New Released: The Next Evolution in Web Development

# Streamlined Directory Structure

 

On a fresh install, the file count has dropped by ~ 69 files. Nice.

Check out our post on this complete new Laravel 11 Directory Structure

So far, these are just a beta preview. They might change, but as of now, here is what to expect...

 

  • Controllers no longer extend anything by default.
  • Config files are gone.
  • No more middleware directory
  •  

Currently, Laravel includes nine middleware and many you would never customize. However, if you do want to customize them, that is moved to the App/ServiceProvider. For example:

-------------------------------------

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

# No more Http/Kernel

Most of the things you used to could do in the Kernel you can now do in the Bootstrap/App.
-------------------------------------
return Application::configure()
->withProviders ()
-›withRouting(
web: __DIR__.'/../routes/web.php'
commands: __DIR__.'/../routes/console.php',
)
->withMiddleware(function(Middleware Smiddleware) {
$middleware->web(append: LaraconMiddleware::class):
})
-------------------------------------

# Model casts changes

 

Model casts are now defined as a method instead of a property. When defined as a method we can do 
other things, like call other methods

directly from the casts. Here is an example using a new Laravel 11 AsEnumCollection:

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

# New Dumpable Trait

 

This aims to streamline the core of the framework since multiple classes currently have "dd" 
or "dump" methods. Plus you can use this Dumpable trait in your own classes:

-------------------------------------

class Stringable implements JsonSerializable, ArrayAccess
{
use Conditionable, Dumpable, Macroable, Tappable;
 
str('foo')->dd();
str('foo')->dump();
-------------------------------------

# Config Changes

Laravel has a lot of config files, and Laravel 11 removes these, and all config options cascade down. The .env

has been expanded to include all the options you'd want to set.

To pair with this is a new config:publish command so you can bring back any config you might want. Even

with bringing them back, the new cascade feature allows you to remove every option you don't want to

customize.

# New Once method

Laravel 11 includes a new once helper method that ensures you'll always get the same value no matter how

many times you call an object method. The once function is helpful when you have some code that you want

to ensure only ever runs one time.

# Slimmed default Migrations

When you start a new Laravel app, it comes with some default migrations from 2014 and 2019. These now will

come with the dates removed and moved into just two files.

# Routes changes

By default, there will be only two route files, console.php and web.php. API routes will now become opt-in via

php artisan install:api, giving you the API routes file and Laravel Sanctum.

The same with websocket broadcasting, php artisan install:broadcasting.

# New up Health Route

Laravel 11 will include a new /up health route that fires a DiagnosingHealthEvent so you can better integrate with up time monitoring.

# APP_KEY Rotation

In older versions of Laravel, if you changed your APP_KEY it could lead to broken data in the database. Laravel 11 has a new graceful rotation which will NOT break old encrypted data, using an APP_PREVIOUS_KEYS .env variable. It will auto re-encrypt the data using new key.

# Console Kernel Removed

The Console Kernel is being removed, and you'll be able to instead define your console commands right in routes/console.php.

# Named Arguments

 

Named arguments are not covered by Laravel's backwards compatibility guidelines. They may choose to 
rename function arguments when necessary in order to improve the Laravel codebase. When calling
Laravel methods using named arguments should be done cautiously and with the understanding that
the parameter names may change in the future.

# Eager Load Limit

 

Laravel 11 integrates the code behind the "eager load limit" package:

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

# When will Laravel 11 be released?

No official date is set other than Q1 2024. At Laracon EU it was hinted that it'll be the first or second week of March 2024.

# PHP 8.2 minimum support

This was an early decision, but Laravel 11 apps require a minimum of PHP 8.2. If you are running an older

version of PHP, now is a good time to get that upgraded.

# SQLite 3.35.0+ required

If you use a SQLite database, then Laravel 11 will require SQLite 3.35.0 or greater.

# Doctrine DBAL Removal

Laravel is no longer dependent on the Doctrine DBAL and registering custom Doctrines types is no longer

necessary for the proper creation and alteration of various column types that previously required custom

types.

# Install Laravel 11

Laravel 11 isn't released yet, but you can start using it and testing it by running Laravel new with the --dev flag:
-------------------------------------
laravel new projectname --dev
-------------------------------------

Keep in mind things will change from now until the official Laravel 11 release.

# Upgrade to Laravel 11

Laravel Shift is the easiest way to upgrade but you can also follow the upgrade guide in the Laravel docs

Img

Written by

Sandeep Gajera

Sandeep Gajera is a Founder and Technical Director at AstroJal Technology. He is dedicated to making the best use of modern technologies to craft end-to-end solutions. He also has a vast knowledge of Cloud management like AWS / Google Cloud. He loves to do coding so still doing the coding. Also, help employees for quality based solutions to clients. Always eager to learn new technology and implement for best solutions.

About Me

Img
Sandeep Gajera

Founder and Technical Director
at AstroJal Technology.

Popular Feeds