Laravel: BroadcastWhen equivalent for events

98 Views Asked by At

I am searching for an equivalent to Laravel's broadcastWhen() function to use it for my events.

Goal is to reduce events placed on the queue by certain conditions.

I tried using a Event which implements the ShouldBroadcast Interface, but surely the event got still fired and received by the listener.

So the idea should kind of look like:

class TestEvent extends Event
{
    use SerializesModels;

    public $message;

    public function __construct(int $message)
    {
        $this->message = $message;
    }

    /**
     * Determine if this event should placed on the queue.
     *
     * @return bool
     */
    public function addToQueueWhen()
    {
        return $message < 0
    }
}

Thanks for your help

0

There are 0 best solutions below