#Vue front end not changing when my reverb websocket events are hit.

4 messages · Page 1 of 1 (latest)

terse sentinel
#

Hi All.

I have a ShouldBroadcast event and I can see in my console browser window (consolewindow.png) that my websocket event is picked up.

I believe (ReverbDebug.png) Confirms this is all setup.

However my vue page does not seem to react to the events, I would appreciate any help or guidance on this. 🙂

For reference websocket is setup as:

<?php

namespace App\Events;

use App\Models\Post;
use Illuminate\Broadcasting\Channel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\InteractsWithSockets;

class PostCreated implements ShouldBroadcast
{
    use InteractsWithSockets, SerializesModels;

    public $message;

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

    // Broadcast on a public channel for all users
    public function broadcastOn(): array
    {
        return [new Channel('posts')];
    }

    public function broadcastAs(): string
    {
        return 'PostCreated';
    }
}

Called with:

use Illuminate\Support\Facades\Broadcast;
broadcast(new PostCreated($post));

I have also tried:

Broadcast::on('posts')
    ->as('PostCreated')
    ->with(['dummy'])
    ->send();

My vue page is simply:

<template>
  <div>
    <h1>Test</h1>
    <p>Console window should have events</p>
  </div>
</template>

<script setup lang="ts">
import { onMounted } from 'vue';
import { useEchoPublic } from '@laravel/echo-vue';

onMounted(() => {
  useEchoPublic('posts', 'PostCreated', (e) => {
    console.log('Event received:', e);
  });
});
</script>
sudden pelican
#

If you just use PostCreated, echo will read event App\Events\PostCreated

terse sentinel
#

Hey thanks @sudden pelican but sadly no luck there, having just given that a go.

Would the event in the browser console window not have a . in front of it too if that was the issue? (And the anonymous event get around this issue?)