1

I'am using Laravel 5.5 with echo for an admin panel , the main guard (web) is related to Admin class , the private channel name that i want to get is Admin.1 ,

The problem is when i change the channel name from

 Echo.private('App.User.' + this.userid)

to

Echo.private('App.Admin.' + this.userid) 

it gets me this error

broadcasting/auth 500 (Internal Server Error)

what i tried is :
i put this

 Broadcast::routes(['middleware' => [ 'api', 'web','auth' ] ]);  

in web.php and api.php and BroadcastServiceProvider.php put it doesn't seem to work i also tried this soltion How to define or pass auth guard for broadcast authentication routes instead of default auth guard?

Mohamed Zayed
  • 191
  • 1
  • 1
  • 11

2 Answers2

0

In your echo settings set authEndpoint to 'broadcasting/auth'. here's the code that works for me after facing the same problem.

new Echo({
    broadcaster: 'pusher',
    key: '{{env("PUSHER_APP_KEY")}}',
    cluster: 'us2',
    encrypted: true,
    authEndpoint: '{!! env("APP_URL") !!}/broadcasting/auth',
});
  • @MohamedZayed Yep, adding only this line along with `Broadcast::routes(['middleware' => [ 'web','auth' ] ]);` did it for me. –  Jan 14 '18 at 13:02
  • though, make sure you are not forgetting to add `{!! env("APP_URL") !!}' and re-check your APP_URL and Pusher configurations if you are using pusher. –  Jan 14 '18 at 13:04
  • instead of APP_URL i hard coded the path and it didn't work – Mohamed Zayed Jan 14 '18 at 13:08
0

I solve my problem by :
adding this to BroadcastServiceProvider

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

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

     /*
     * for auth user channel
     */
      Broadcast::channel('App.Admin.{id}',function($user, $id){
          return (int) $user->id === (int) $id;
      });
}
Mohamed Zayed
  • 191
  • 1
  • 1
  • 11