Laravel 11.5 has just been released, and it added anonymous broadcasting
. What is it? Let's take a look.
This message is triggered by a private anonymous event, so let's see how it's done.
Global Anonymous Events
We want to start by re-creating our first example from the previous lesson—a global event that will inform all users about system maintenance. We will use the same event and channel, but this time, we will make it anonymous.
To create a channel for this, we will modify the routes/channels.php
file:
// ... Broadcast::channel('system-maintenance', function () { // Public Channel});
Then, we want to create a new command to trigger this event:
php artisan make:command SystemNotifyMaintenanceCommand
And modify the command file:
app/Console/Commands/SystemNotifyMaintenanceCommand.php
use Illuminate\Console\Command;use Illuminate\Support\Facades\Broadcast; class SystemNotifyMaintenanceCommand extends Command{ protected $signature = 'system:notify-maintenance'; protected $description = 'Command description'; public function handle(): void { $time = $this->ask('When should it happen?'); Broadcast::on('system-maintenance') ->as('App\\Events\\SystemMaintenanceEvent') ->with([ 'time' => $time ]) ->via('reverb') ->send(); }}
Next, we will add a...