laravel / echo

Laravel Echo library for beautiful Pusher and Ably integration.
https://laravel.com/docs/broadcasting#client-side-installation
MIT License
1.17k stars 179 forks source link

Fatal error when using channel.listen #392

Closed bicicura closed 6 months ago

bicicura commented 6 months ago

Echo Version

1.16.0

Laravel Version

9.2

PHP Version

8.0.2

NPM Version

9.3.1

Database Driver & Version

No response

Description

When trying to listen for a channel:

myChannel.listen('alertasContador', payload => {})

I got this fatal error: image

Event configuration:

<?php

namespace App\Events;

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

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

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(public $cantidad)
    {
    }

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

    /**
     * The event's broadcast name.
     */
    public function broadcastAs(): string
    {
        return 'alertasContador';
    }

}

Event route configuration:

<?php

use Illuminate\Support\Facades\Broadcast;

Broadcast::channel('alertas-cantidad', function() {
    return true;
});

[!NOTE] I am trying to connect to a public channel.

Steps To Reproduce

  1. Create a public channel in Laravel.
  2. Connect to channel using Laravel Echo.
  3. Try to listen to event.
driesvints commented 6 months ago

Does it work for you on v1.15.3?

bicicura commented 6 months ago

@driesvints Thanks for the quick response! I had the same issue with v1.15.3

driesvints commented 6 months ago

Hey there,

Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to open up a new issue with a link to the original one and we'll gladly help you out.

Thanks!