1134

Laravel 11 is coming soon! – What enhancements are anticipated & how to upgrade website or app?

By: Skynet Technologies USA LLC
8 mins
500
Laravel 11

Laravel 11 will be releasing in Q1 2024, and its lifespan will be till February 2026 (according to Laravel support policy ). Here you must note that Laravel 10 will get bug fixes until August 2024. Thus, your system will need updates; however, the updates are not required immediately. Laravel’s each version has two years of support from community, which provides enough time to upgrade your existing systems.

The upcoming version is expected to bring an array of exciting new features. Though it is still in beta phase and subject to change, some of the features and modifications can be seen in PR (pull request) on GitHub. Have a look!

YOU MIGHT ALSO LIKE: How to upgrade Laravel 9 to 10

Laravel 11 – Release Preparations

Here is a list on how to prepare for the Laravel 11 release, as of now. It might get changed with time, as more details on release will be out later.

  • Set up Laravel 11
  • Update Testbench dependencies
  • Remove old WithoutEvents traits.

YOU MIGHT ALSO LIKE: Laravel Packages

Laravel 11 – New Features and Changes

1. PHP 8.1 will not be supported

PHP 8.2 will be fully established by the time Laravel 11 will be up for public use and PHP 8.3 will be stable as well. When two updated versions will be there, why support an older version? Thus, Laravel can stop supporting PHP 8.1. However, this is not an urgent requirement and can be done slowly by performing extensive testing. Currently, you have ample time to update your projects.

Check the GitHub pull request.

2. A more minimalistic and sleek application skeleton

This is one profound addition that Laravel 11 will come with a slimmer application skeleton. And the only motive behind this enhancement is that you will not need to deal with huge boilerplate code. The fewer the codes, the faster development will be. Let’s see what all changes are expected in this regard:

Now framework will automatically discover $policies property. Thus, they are removed in AuthServiceProvider.

The base EventServiceProvider will now manage registering SendEmailVerificationNotification thereby it is no longer necessary in EventServiceProvider. Moreover, auto-event discovery is enabled by default now.

BroadcastServiceProvider has been removed in Laravel 11 for it is not necessary now. The framework is not automatically loading the routes/channels.php file.

RedirectIfAuthenticated is now seamless because base one is in the framework’s internals.

No more calls from authenticate middleware to redirectTo() for JSON routes. It will vanish an unwanted ternary check.

The new skeleton also removed ValidateSignature, ValidateCsrfToken, EncryptCookies, PreventRequestsDuringMaintenance.php, TrustHosts, TrustProxies, and TrimStrings middleware.

Now in Laravel 11, no need to call the load() method in the console kernel because Custom Artisan commands will now load automatically.

Closure-based Artisan commands can be registered in the console kernel thereby routes/console.php have been removed.

A few migrations have been merged into a single file or removed.

Now base controller doesn’t have AuthorizesRequests and ValidatesRequests traits. They both have been removed.

The exception handler is also removed from Laravel 11.

The bootstrap/app.php file has been shrunk to only three lines of code.

YOU MIGHT ALSO LIKE: Laravel Microservices

3. Dumpable concern – (dump () and dd () from your objects)

The main idea behind this pull request is to replace the current dd and dump methods in most Laravel’s classes and it will introduce a new Dumpable trait as well. By utilizing the new trait, Laravel users and package authors will be able to include debugging methods within their classes easily.

A code example to explain this concept:

<?php

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();

4. More convenient Model::casts() method

You declare attribute casting in an Eloquent model in Laravel like:

class User extends Model {
  protected $casts = [
    'email_verified_at' => 'datetime',
  ];
}

The new update helps you to define your casting through a casts() method in your model now. It will give you a chance to use static methods from the class doing the casting.

class User extends Model {
  protected function casts(): array {
    return [
      'foo' => AsCollection::using(FooCollection::class),
    ];
  }
}

Additionally, now you will be able to specify your casts as an array.

class User extends Model {
  // Even in the old $casts property!
  protected $casts = [
    'foo' => [AsCollection::class, FooCollection::class],
  ];

  protected function casts() : array {
    return [
      'foo' => [AsCollection::class, FooCollection::class],
    ];
  }
}

The casts() method is prioritized over the $casts property.

Interestingly, the changes are non-breaking. So, they will not impact your existing code whenever you update to Laravel 11.

You can check the pull request.

YOU MIGHT ALSO LIKE: Laravel vs Symfony

Wrapping up

These are a few changes that are based on the pull requests. Though Laravel 11 will have more than these modifications. Until its final documentation release, begin updating your current system.

Moreover, there is an exciting opportunity for you to become a part of Laravel 11 development.

You can check what is going on with Laravel 11 on GitHub. All the pull requests will let you know about new changes that have been made.

If you have any pain points with the framework, create a solution for the same.

Then send the PR to the laravel/framework repository, gather feedback, improve, and get merged with upcoming Laravel 11.

If you create something that will be not only useful for developers but also easy to maintain for the Laravel makers, then more likely your solution will get merged.

Skynet Technologies stands as a prominent Laravel development company, offering a wide range of specialized Laravel development services. Our team excels in diverse domains, encompassing Laravel customization, migration, integration, extension development, Laravel ecommerce development, template design, as well as maintenance and support.

No matter if you require a tailor-made Laravel web application or a dedicated team of Laravel developers, we've got you covered. Our highly skilled professionals are adept at crafting top-notch Laravel custom web applications designed precisely to suit your unique needs. To request a free quote, simply fill out the form below or send us an email at [email protected].