When you call "Handle" it will create again the event() I think Maybe you should remove "event(new AbcNotificationCreated($event));" and test it out.
Mar 9, 2019
3
Level 32
Event got fired twice
In my app i want to make notification realtime which Laravel Spark don't ship in default installation. Whenever a notification created Laravel Spark fire NotificationCreated event.
Laravel\Spark\Events\NotificationCreated
i have setup listener in my app to listen to this event and fire my own custom event
public function handle(NotificationCreated $event)
{
dump('done');
event(new AbcNotificationCreated($event));
return false;
}
This is my AbcNotification
<?php
namespace App\Events;
use App\Task;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class AbcNotificationCreated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $notification;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($notification)
{
$this->notification = $notification;
$this->dontBroadcastToCurrentUser();
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('notification');
}
}
By default Spark don't Broadcast NotificationCreated event on any channel so i have to create my own custom event which broadcast notification for frontend to listen and react in realtime.
But the problem is AbcNotificationCreated event got fired twice. PS: Any help or suggestion appreciated
Please or to participate in this conversation.