Anonymous Event Broadcasting in Laravel 11.5

This week, the Laravel team released v11.5, with anonymous event broadcasting, Blade performance improvements, generating URLs with query parameters, and more.

Anonymous Event Broadcasting

Joe Dixon contributed anonymous broadcasts in Laravel for real-time applications using Laravel Echo:

Sometimes you may wish to broadcast an ad-hoc event.

An ad-hoc event is one where you don't need to hook into it anywhere else in your application. You just want to notify the frontend of something.

For this, you don't want to go to the trouble of creating a brand new event, you just want to fire off a message.

For this, we can use an anonymous broadcast using the Broadcast facade, which can be as simple as:

Broadcast::on('my-channel')->send();

// You may dispatch to multiple channels at the same time:
Broadcast::on([
    'my-channel',
    new PrivateChannel('my-channel'),
    'presence-my-channel'
)->send();

// Broadcast the anonymous event on a private or presence channel
Broadcast::private('my-channel')->send();
Broadcast::presence('my-channel')->send();

To learn more about anonymous event broadcasting in Laravel, check out Laravel's Documentation.

Blade Performance Improvements

Taylor Otwell shared a thought about supercharging Blade component rendering performance. Two pull requests were accepted and merged as part of Laravel 11.5, which collectively improved Blade rendering by 20%:

Ability to Generate URLs With Query Params

Steve Bauman contributed the ability to generate URLs with query parameters via the new query() method:

// http://localhost/products?sort=-name
url()->query('products', ['sort' => '-name']);

// http://localhost/products?columns[0]=name&columns[1]=price&columns[2]=quantity
url()->query('products', ['columns' => ['name', 'price', 'quantity']]);

// Overiding parameters:
// http://localhost/products?sort=-price
url()->query('products?sort=-name', ['sort' => '-price']);

// Appending parameters
// http://localhost/products?sort=-name&search=samsung
url()->query('products?sort=-name', ['search' => 'samsung']);

Add a Default Namespace for make:trait and make:interface

@milwad-dev contributed a default namespace for make:trait and make:interface, which will create these classes in the following paths if they exist:

If any of those folders exist in your project, Laravel will create the file in that namespace. For example, App\Contracts would take precedence over App\Interfaces. Lastly, the file is created in the App namespace directly if either of the directories are not found.

Release notes

You can see the complete list of new features and updates below and the diff between 11.4.0 and 11.5.0 on GitHub. The following release notes are directly from the changelog:

v11.5.0


The post Anonymous Event Broadcasting in Laravel 11.5 appeared first on Laravel News.

Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.