christophrumpel / blog-laravel-real-time-notifications

47 stars 28 forks source link

No notifications or events showed in browser #2

Open neoacevedo opened 3 years ago

neoacevedo commented 3 years ago

I have tried to implement it as in my project with a very few changes (I don't use the User model but I use Admin model under App namespace) but I don't see any console log in the browser, and the auth data is empty:

{"event":"pusher:subscribe","data":{"auth":"","channel":"App.Admin.2"}}
christophrumpel commented 3 years ago

Hey, it is very difficult to debug such an issue. Just from your info, I can't tell what the issue could be. I would start by trying to make it work exactly like in my tutorial to see if it works like that from you. If yes, then the issue must lie in your changes or your app, if not, the issue must lie somewhere else. This is what I would do to try to figure out what could be the issue.

neoacevedo commented 3 years ago

I use L6, the model is App\Admin with Notifiable.

The Echo javascript is:

Echo.private('App.Admin.{{Auth::user()->id}}')
         .notification((notification) => {
             console.log(notification.message);
         });

The channel route (with admin guard) is:

Broadcast::channel('App.Admin.{id}', function ($admin, $id) {
    return (int) $admin->id === (int) $id;
}, ["guards" => ["admin"]]);

The Admin user is logged in via admin middleware, not web middleware.

I copied your RealTimeMessage.php and RealTimeNotification.php files inside my project.

With tinker, I test:

event(new App\Events\RealTimeMessage('Hello World'));
...
$admin = Admin::find(2); // the current logged in admin.

$admin->notify(new App\Notifications\RealTimeNotification('Hello World'));

But none of the notifications nor listening events are displayed in the browser console.

christophrumpel commented 3 years ago

Have checked that connection on the WebSockets dashboard shows that your WebSockets server is connected? Have you made this work with the demo I showed in the article? As mentioned, I would first check that.

neoacevedo commented 3 years ago

Good, I don't have a clue why, but, without touching anything, it started to work today, good, the event part, but I could see at least working it what is enough to me at the moment.

christophrumpel commented 3 years ago

Cool, hope this helps you to move on from here 👍 (Let me here if you find the issue please)

Jagdish-J-P commented 3 years ago

There must be issue of config cache.

If anyone face this issue, just try after clearing config cache.

php artisan config:cache

I was facing similar issue while trying demo shown on Pusher.