Anonymous Event Broadcasting in Laravel 11.5
Published on by Paul Redmond
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 channelBroadcast::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=-nameurl()->query('products', ['sort' => '-name']); // http://localhost/products?columns[0]=name&columns[1]=price&columns[2]=quantityurl()->query('products', ['columns' => ['name', 'price', 'quantity']]); // Overiding parameters:// http://localhost/products?sort=-priceurl()->query('products?sort=-name', ['sort' => '-price']); // Appending parameters// http://localhost/products?sort=-name&search=samsungurl()->query('products?sort=-name', ['search' => 'samsung']);
make:trait
and make:interface
Add a Default Namespace for @milwad-dev contributed a default namespace for make:trait
and make:interface
, which will create these classes in the following paths if they exist:
- Interfaces:
-
App\Contracts
-
App\Interfaces
-
- Traits:
-
App\Concerns
-
App\Traits
-
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
- [11.x] Add namespace for
make:trait
andmake:interface
command by @milwad-dev in https://github.com/laravel/framework/pull/51083 - [11.x] Ability to generate URL's with query params by @stevebauman in https://github.com/laravel/framework/pull/51075
- [11.x] Adds anonymous broadcasting by @joedixon in https://github.com/laravel/framework/pull/51082
- [10.x] Binding order is incorrect when using cursor paginate with multiple unions with a where by @thijsvdanker in https://github.com/laravel/framework/pull/50884
- [10.x] Fix cursor paginate with union and column alias by @thijsvdanker in https://github.com/laravel/framework/pull/50882
- [11.x] Fix typo in tests by @milwad-dev in https://github.com/laravel/framework/pull/51093
- Fix argument type in
Cache\Store
by @GromNaN in https://github.com/laravel/framework/pull/51100 - Correct comment's grammatical and semantic errors by @javadihugo in https://github.com/laravel/framework/pull/51101
- [11.x] Replace matches typehint fix by @henzeb in https://github.com/laravel/framework/pull/51095
- [11.x] Exclude
laravel_through_key
when replicating model, fixes #51097 by @levu42 in https://github.com/laravel/framework/pull/51098 - [11.x] Add enum types to static Rule methods by @erik-perri in https://github.com/laravel/framework/pull/51090
- [11.x] Add decrement method to the rate limiter class by @AlexJump24 in https://github.com/laravel/framework/pull/51102
- [11.x] Remove dead code by @michaelnabil230 in https://github.com/laravel/framework/pull/51106
- [11.x] Fix support for other hashing implementations when using
hashed
cast by @j3j5 in https://github.com/laravel/framework/pull/51112 - Revert "[11.x] Adds support for
int
backed enums to implicitEnum
route binding" by @driesvints in https://github.com/laravel/framework/pull/51119 - [11.x] Add support for enums in
whereIn
route constraints by @osbre in https://github.com/laravel/framework/pull/51121 - Clarify that \Illuminate\Http\Request::replace replace all input values by @treyssatvincent in https://github.com/laravel/framework/pull/51123
- [11.x] Fix db:show's --counts option by @xuchunyang in https://github.com/laravel/framework/pull/51140
- Update RuntimeException message when no data has been found by @mikemeijer in https://github.com/laravel/framework/pull/51133
- [11] Update DetectsLostConnections.php by @it-can in https://github.com/laravel/framework/pull/51127
- [11.x] Reset connection after migrate for FreshCommand by @driesvints in https://github.com/laravel/framework/pull/51167
- [10.x] Address Null Parameter Deprecations in UrlGenerator by @aldobarr in https://github.com/laravel/framework/pull/51148
- [11.x] Provide context for NestedRules by @imahmood in https://github.com/laravel/framework/pull/51160
- [11.x] Fix renaming columns with
NULL
as default on legacy MariaDB/MySQL by @hafezdivandari in https://github.com/laravel/framework/pull/51177 - [11.x] Supercharge Blade by @assertchris in https://github.com/laravel/framework/pull/51143
- [11.x] Allow implicit binding to have optional backed enums by @Neol3108 in https://github.com/laravel/framework/pull/51178
- [11.x] Blade Component Loop Speed Improvement by @lonnylot in https://github.com/laravel/framework/pull/51158
- [11.x] Fix normalizedNameCache by @Jubeki in https://github.com/laravel/framework/pull/51185
- [11.x] GenericUser use
getAuthPasswordName
instead of hardcoded column name by @Daniel-H123 in https://github.com/laravel/framework/pull/51186