Hi @orhdoga, when you use a private channel, first it makes an authentication that will bring a token that will be used on pusher later. Check if that your '/auth' request on the network tab of your browser is not giving you a 404 or another bad status code. That request is done automatically by laravel echo.
Feb 22, 2020
4
Level 2
Laravel Pusher Doesn't Join Private Channel
Hey, there. So I'm using Laravel 5.8, and I have this problem in which my Laravel Echo code doesn't trigger Pusher to join a private channel. When I switch things up to a public channel, everything seems to work fine. This is how my code looks like:
In App\Events\ProfileUpdated:
<?php
namespace App\Events;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class ProfileUpdated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
// return new PrivateChannel('Profile.' . $this->user->id);
return new PrivateChannel('Profile');
}
}
In routes\channels.php:
<?php
// Criteria on which a user is allowed to listen to the defined channel
// Broadcast::channel('Profile.{id}', function ($user, $id) {
// return (int) $user->id === (int) auth()->user()->id;
// });
Broadcast::channel('Profile', function () {
return true;
});
In UserProfileComponent.vue:
created() {
// Doesn't join private channel for some reason
// window.Echo.private('Profile.' + this.authUser.id)
window.Echo.private('Profile')
.listen('ProfileUpdated', ({user}) => {
// Code to be executed
});
},
Pusher debug console output:
I hope someone can understand better what is going on! Thanks in advance.
Level 25
well, maybe, so the request to /auth is not happening? maybe as you said, now the request should be happening in /en/auth
Please or to participate in this conversation.