Any reason for not using echo?
Also be sure your queue is running, as broadcasting is done on the queue
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi , a have todo list , and i want to make it real-time so i learn it and i make many search and every one has his own way but i follow the documentation of pusher ,
#broadcasting.php
'default' => env('BROADCAST_DRIVER', 'pusher'),
/*
|--------------------------------------------------------------------------
| Broadcast Connections
|--------------------------------------------------------------------------
|
| Here you may define all of the broadcast connections that will be used
| to broadcast events to other systems or over websockets. Samples of
| each available type of connection are provided inside this array.
|
*/
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'host' => env('PUSHER_HOST') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com',
'port' => env('PUSHER_PORT', 443),
'scheme' => env('PUSHER_SCHEME', 'https'),
'encrypted' => true,
'useTLS' => true,
'cluster' => 'eu',
],
'client_options' => [
// Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
],
],
// There's More About More Drivers
and the js code
// Enable pusher logging - No need to add in Production
Pusher.logToConsole = true;
// Initialization the Pusher JS library
var pusher = new Pusher('88e543e3fd1a8705aae2', {
cluster: 'eu'
});
// Subscribe to the channel we specified in our Laravel Event
var channel = pusher.subscribe('public');
channel.bind('public-event', function(data) {
alert(JSON.stringify(data));
});
the view
<script src="https://js.pusher.com/7.2/pusher.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
$('[href="#tab1"]')[0].addEventListener('click',async function (){
axios.get("{{route('control.target.test.targets')}}",{
headers:{
'Content-Type': 'application/json;charset=utf-8',
'X-CSRF-TOKEN': "{{csrf_token()}}"
}
})
});
</script>
and the event
use Dispatchable, InteractsWithSockets, SerializesModels;
public string $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(String $message)
{
$this->message = $message;
}
public function broadcastOn(): array
{
return ['public'];
}
public function broadcastAs()
{
return 'public-event';
}
The Controller
public function index()
{
return response()
->view('target.index');
}
public function create()
{
event(new PublicEvent('hello world'));
return 'Done';
}
And My Routes
Route::get('/my-targets',[TargetsController::class,'index'])->name('user.targets');
Route::get('/fire-event',[TargetsController::class,'create'])->name('test.targets');
@MahmoudAdelAli can you show your broadcasting class? https://laravel.com/docs/9.x/broadcasting#defining-broadcast-events is that the PublicEvent class? I see some of a class in the first post but alot is missing?
Please or to participate in this conversation.