You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
...Broadcast::channel('EveryoneChannel', function () {
returntrue;
});
...
Create new event php artisan make:event EveryoneEvent and edit
<?phpnamespaceApp\Events;
useIlluminate\Broadcasting\Channel;
useIlluminate\Broadcasting\InteractsWithSockets;
useIlluminate\Contracts\Broadcasting\ShouldBroadcast;
useIlluminate\Foundation\Events\Dispatchable;
useIlluminate\Queue\SerializesModels;
classEveryoneEventimplementsShouldBroadcast
{
useDispatchable, InteractsWithSockets, SerializesModels;
/** * The name of the queue connection to use when broadcasting the event. * * @var string */public$connection = 'redis';
/** * The name of the queue on which to place the broadcasting job. * * @var string */public$queue = 'default';
/** * Create a new event instance. * * @return void */publicfunction__construct()
{
//
}
/** * Get the channels the event should broadcast on. * * @return \Illuminate\Broadcasting\Channel|array */publicfunctionbroadcastOn()
{
returnnewChannel('EveryoneChannel');
}
/* * The Event's broadcast name. * * @return string */publicfunctionbroadcastAs()
{
return'EveryoneMessage';
}
/* * Get the data to broadcast. * * @return array */publicfunctionbroadcastWith()
{
return [
'message'=> 'Hello!'
];
}
}
Add route for send and receiver broadcast at file routes/web.php
...Route::get('/send', function () {
broadcast(newApp\Events\EveryoneEvent());
returnresponse('Sent');
});
Route::get('/receiver', function () {
returnview('receiver');
});
...
Create new view resources/views/receiver.blade.php
Alif