#Laravel Event broadcastWith() method not working

5 messages · Page 1 of 1 (latest)

hallow cloud
#
<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class TaskCreated implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    /**
     * The task that was created.
     *
     * @var \App\Models\Task
     */
    public $task;

    /**
     * Create a new event instance.
     *
     * @param \App\Models\Task $task
     * @return void
     */
    public function __construct($task)
    {
        $this->task = $task;
    }


    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('task');
    }

    /**
     * Get the data to broadcast.
     *
     * @return array
     */
    public function broadcastWith()
    {
        return ['catalogue_id' => $this->task->catalogue->id];
    }

    /**
     * Determine if this event should broadcast.
     *
     * @return bool
     */
    public function broadcastWhen()
    {
        return $this->task->catalogue->users->count() > 1;
    }

}

#

I am still getting the whole public property in the payload instead of only the data specified.

#

I am listening via Livewire.

#

Laravel Event broadcastWith() method not working

#

Laravel Event php broadcastWith() method not working