In my application i have two separated sections for users and admins which i used Auth::guard() to authenticate them.
in my dashboard (admin guard) i used Laravel Echo (pusher) to show live notifications. echo tries to authenticate for incoming messages automatically by sending an XHR request to /broadcasting/auth, and it fails, because in PusherBroadcasting.php line 38 you check for authenticated user in request.
the problem is that my dashboard is using token header to send xhr requests to my controllers, and i have my own middleware to check for that. so. as you can see there is no user at $request->user().
i had to remove line 38-42 in order to fix this problem temporarily.
You can pass route parameters to the broadcasting routes:
Broadcast::routes(['middleware' => ['web', 'myMiddleware']]);
thanks! but when i want to use it it triggers this error:
Class App\Http\Controllers\Illuminate\Broadcasting\BroadcastController does not exist.
is it possible to change authenticated user for reach guard? i need App\Admin to be logged in for my admin section and App\User for my user panel. is it possible with your solution?
You have to put Broadcast::routes(); into the api.php routes file.
getting error
Class App\Http\Controllers\Illuminate\Broadcasting\BroadcastController does not exist
Most helpful comment
You can pass route parameters to the broadcasting routes: