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

asufayran's avatar

Laravel Echo Not Working

Hi guys, I need to implement Laravel Echo in my project for broadcasting, and I have followed the documentation precisely, but Echo does not seem to be working, since events do come to pusher debug console, but i'm not able to see them in the browser. below are the most important pieces of code:

.env:

BROADCAST_DRIVER=pusher

PUSHER_APP_ID=0000000000000
PUSHER_APP_KEY=-----------------------------
PUSHER_APP_SECRET=-----------------------
PUSHER_APP_CLUSTER=ap2

broadcasting:


    'default' => env('BROADCAST_DRIVER', 'pusher'),

    /*
    |--------------------------------------------------------------------------
    | Broadcast Connections
    |--------------------------------------------------------------------------
    |
    | Here you may define all of the broadcast connections that will be used
    | to broadcast events to other systems or over websockets. Samples of
    | each available type of connection are provided inside this array.
    |
    */

    'connections' => [

        'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER'),
                'useTLS' => true,
            ],
        ],

channels.php (PS. note: always returned true in logs):


Broadcast::channel('App.User.{id}', function ($user, $id) {
    \Illuminate\Support\Facades\Log::info("Load from channel");
    \Illuminate\Support\Facades\Log::info((int) $user->id === (int) $id);
    return (int) $user->id === (int) $id;
});

FavoriteCreate.php:

FavoriteCreated implements ShouldBroadcast

/**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('App.User.' . $this->favorite->favorable->id);
    }

    public function broadcastAs()
    {
        return 'favorite.created';
    }

app.blade.php: (I suspect that defer may have something to do with it):


        <main class="py-4">
            @yield('content')
        </main>
    </div>
    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}"></script>
    @yield('js')

BroadcastingServiceProvider.php:

public function boot()
    {
        Broadcast::routes();

        require base_path('routes/channels.php');
    }

bootstrap.js

import Echo from 'laravel-echo';

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: '00000000000000',
    cluster: 'ap2',
    forceTLS: true
});

webpack.mix.js:

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .sourceMaps();

NotificationsComponent.vue:

created() {
        Echo.private('App.User.'+this.user)
        .listen('favorite-created', (e) => {
            console.log(e);
        })
    }

Pusher DebugConsole:

API MESSAGE
‌

Channel: private-App.User.3, Event: Illuminate\Notifications\Events\BroadcastNotificationCreated

06:00:45

API MESSAGE
‌

Channel: private-App.User.3, Event: favorite.created

Any help is highly appreciated since I have been working on this for the last four days without any success.

0 likes
6 replies
drehimself's avatar

I always initially run into issues when working with Private channels. Maybe try working with public channels first to see if you can see the messages in the browser. Once you get public channels working, convert it over to Private channels.

Are you getting any error messages in your browser console?

I have a video showing the entire process, it's a bit old but still relevant I think: https://www.youtube.com/watch?v=pjK0VMTCtVg

Hope you figure it out.

2 likes
asufayran's avatar

Thank you Andre. I did try with public channels and it didn’t work and without any errors in the browser just like now. The only time it worked for me is when I used pusher js listener directly, and it was a public channel. But I will try your video again, and see what I come up with

tricki's avatar

You broadcast the event as "favorite.created" but listen to "favorite-created" (dash instead of a period)

asufayran's avatar

@tricki it is not that. I had a typo in this question, which i fixed when i posted to stackoverflow, but forgot to fix here. Also, i tried to listen to the notification event without any luck

asufayran's avatar

So I have finally figured it out. the problem was with this line and it's place in app.blade.php

    <script src="{{ asset('js/app.js') }}"></script>

changed it to:

    <meta name="csrf-token" content="{{ csrf_token() }}">
    <script src="{{ asset('js/app.js') }}" defer></script>

I also had to import jQuery separately and not use the one in app.js

Please or to participate in this conversation.