Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vinaysoni1910's avatar

How to pass laravel echo event to livewire component?

Hi Everyone! I am trying to implement pusher and echo in project. I am still learning and I checked the documentation and forum articles as well. I am not able to figure out what's wrong with the code.

I am trying to render listing on real time in admin panel whenever I create a new form from user end.

Here is my code:

class FormSubmitted implements ShouldBroadcastNow { use Dispatchable, InteractsWithSockets, SerializesModels;

/**
 * Create a new event instance.
 */
public $formData;

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

/**
 * Get the channels the event should broadcast on.
 *
 * @return array<int, \Illuminate\Broadcasting\Channel>
 */
public function broadcastOn(): array
{
    return [
        new Channel('forms'),
    ];
}

}

I blade file I have created a livewire component and passing $form for listing.

                <tbody >
                    @forelse ($forms as $key=>$form)
                    <livewire:form-table-body :forms="$form" />
                    @empty
                    @endforelse
                </tbody>

This is my script added under blade file

<script type="module">
    Echo.channel('forms')
        .listen('FormSubmitted', (event) => {
            Livewire.emit('formDataUpdated', event.formData);
        });
</script>

This is livewire function

0 likes
0 replies

Please or to participate in this conversation.