[Vuejs]-Laravel vue pusher – broadcasting on private channels not working

0👍

  1. You need to pass the $user and $o variables into your broadcast route callback and wrap the parameter definition in curly braces:
Broadcast::channel('osc{o}', function($user, Order $o) { ... });
  1. When you don’t want echo to prefix the entire event namespace to your event, you need to prefix your event name (on the front-end only) with a .:
.listen('.oscEvent', (e) ...
  1. In your oscEvent class, you should type-hint the $order parameter in the constructor:
public function __construct(Order $order) { ... }
  1. Without seeing the Echo initialization, it’s hard to tell if you’ve configured it correctly for authentication. Did you add the csrf token to the page so echo could pick it up?

From the Laravel docs:

Laravel Echo will need access to the current session’s CSRF token. You should verify that your application’s head HTML element defines a meta tag containing the CSRF token:

<meta name="csrf-token" content="{{ csrf_token() }}">
  1. Make sure Broadcast::routes(); is called in your BroadcastServiceProvider::boot method.

Hope this helps.

NOTE

I’m thinking you probably do want to prefix the entire namespace to your event, so you can probably ignore suggestion #2

0👍

It still does not work.

  1. I modified channel callback

     Broadcast::channel('osc{o}', function ($user,Order $o) {
     return (int) $user === (int) $o->user_id;
    });
    
  2. I made type-hint Order class.

  3. I’m extending “layouts.app” template in my user and admin views.
  4. Yes, it is called.

I’m using laravel 5.6.

Leave a comment