laravel 11

Laravel 11 has been released, see the features and changes

Good news for Laravel devs, Laravel 11 was released on 12 March. In the latest Laravel 11 introduces many features like minimal application structure, Reverb, blazing fast web sockets and much more. So, let’s dive deeper into this blog to know more about features and changes in detail.

Laravel 11 features and changes

In laravel 11 have many features that can benefit many businesses. So, let’s begin with this year’s Laravel 11 update.r

SQLite by default

By default, In laravel 11 uses SQLite by default for database storage. when creating a project using composer create project command or via laravel installer it will automatically create the SQLite file and run the initial database migrations.

No support of php 8.1

laravel 11 is no longer supports php 8.1. Users have to upgrade the php 8.1 to php 8.2 in order to install laravel 11. However it is not necessary to install latest version, firstly upgrade your project for testing purpose if everything works fine then you can switch or upgrade your existing project to latest laravel 11.

Laravel Reverb

Laravel reverb gives high speed and scalable real time web socket communication directly to your laravel application. It integrates with Laravel’s existing suite of event broadcasting tools like Laravel Echo

php artisan reverb:start

Reverb also allows for horizontal scaling using the Redis publish and subscribe features allowing you to distribute websocket traffic across various reverse backend servers.

Minimalistic application skeleton

Laravel 11 has a slimmer skeleton. The intent here is to involve less boilerplate code. This approach will benefit the business owners and developers by allowing them to deal with less code, leading to faster development. Let’s talk about the changes made in-depth, they are all as follows:

  1. Within the ‘AuthServiceProvider,’ the ‘$policies’ are removed as the framework discovers them automatically.
  2. In the ‘EventServiceProvider,’ the ‘SendEmailVerificationNotification’ is no longer necessary, as the base ‘EventServiceProvider’ is registering it. Also, you will notice that the auto-event discovery is now enabled by default.
  3. ‘BroadcastServiceProvider’ is not needed anymore and, therefore, is removed. The framework is not automatically loading the routes/channels.php file.
  4. ‘RedirectIfAuthenticated’ is simpler due to the base one in the framework’s internals.
  5. The ‘Authenticate’ middleware now does not call the ‘redirectTo()’ for the JSON routes, thereby removing the unnecessary ternary checks.
  6. All the ‘EncryptCookies,’ ‘PreventRequestsDuringMaintenance.php,’ ‘TrimStrings,’ ‘TrustHosts,’ ‘TrustProxies,’ ‘ValidateCsrfToken’ and ‘ValidateSignature’ middleware are removed from the skeleton structure.
  7. The Custom Artisan is loaded automatically with Laravel 11, and the console does not need to call the ‘load()’ method.
  8. The routes/console.php have been removed. The closure-based artisan commands can now be registered only in the console kernel..
  9. Various other migrations are either consolidated into a single file or removed.
  10. The ‘AuthorizesRequests’ and ‘ValidatesRequests’ traits have been removed from the base controller.
  11. The bootstrap/app.php file has been reduced in size, now with only three lines of code.
  12. The exception handler is also removed in the Laravel v11.

Per second rate limiting

In Laravel 11, you can set the rate limit per second, along with the HTTP requests and queued jobs. In laravel previous versions it was limited to one minute.

RateLimiter::for(‘invoices’, function (Request $request) {
return Limit::perSecond(1);
});

Queue Interaction Testing

In previous versions when testing that a queued job was released, deleted or manually failed with heavy task and required the definition of custom queue fakes and stubs. However in laravel 11 you may easily test for these queue interactions using the withFakeQueueInteractions method

<?php

use App\Jobs\ProcessPodcast;

it(‘may release a job with a delay’, function () {
$job = (new ProcessPodcast)->withFakeQueueInteractions();

$job->handle();

$job->assertReleased(dalay: 30);
});

the assertReleased assertion, which allows you to verify if a job was released back into the queue. you may also use the assertFailed or assertDeleted assertions to determine if a job has failed or been deleted, respectively.

Graceful Encryption Key Rotation

laravel can encrypt cookies, including your application session cookies, essentially every laravel application request depends on encryption. Besides, because of this, rotating your application’s encryption key would log out all users from your application. In addition, decrypting data that was encrypted by the previous encryption key becomes impossible.
Laravel 11 allows you to define your application’s previous encryption keys as a comma-delimited list via the APP_PREVIOUS_KEYS environment variable.

‘cipher’ => ‘AES-256-CBC’ ,
‘key’ => env(‘APP_KEY’),
‘previous_keys’ => [

  …array_filter(

          explode(‘ , ‘ ,env(‘ ,APP_PREVIOUS_KEYS’, ”))

);

];

When encrypting values, Laravel will always use the “current” encryption key, which is within the APP_KEY environment variable. When decrypting values, Laravel will first try the current key. If decryption fails using the current key, Laravel will try all previous keys until one of the keys is able to decrypt the value.

This approach to graceful decryption allows users to keep using your laravel application even if your encryption key is rotated. Check out the release notes.

Go To Top