У меня ошибка на эхо-сервере laravel, при присоединении private-user-1
MYERROR
[3:22:51 PM] - Preparing authentication request to: http://radhakishan.laravel6.com
[3:22:51 PM] - Sending auth request to: http://radhakishan.laravel6.com/broadcasting/auth
[3:22:52 PM] - sNrKAzpEsjxjnhKwAAAA could not be authenticated to private-user.1{....}
Client can not be authenticated, got HTTP status 404
У меня уже естьустановил эти пакеты
1.Package.json установил пакеты
"laravel-echo": "^1.6.1",
"pusher-js": "^5.0.2",
"socket.io": "^2.3.0",
"socket.io-client": "^2.3.0"
2.Composer.json установил пакеты
"require": {
"php": "^7.2",
"encore/laravel-admin": "^1.7",
"fideloper/proxy": "^4.0",
"laravel/framework": "^6.0",
"laravel/tinker": "^1.0",
"predis/predis": "^1.1",
"pusher/pusher-php-server": "^4.0"
},
3.config / app.php у меня естья уже установил
App\Providers\BroadcastServiceProvider::class,
4.config / broadcasting.php
Я уже установил вещатель по умолчанию
'default' => env('BROADCAST_DRIVER', 'redis'),
5.routs / channel.php Я уже установил
Broadcast::channel('user.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
6.Мой файл событий
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class UserMessage
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($message)
{
$this->message = $message;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('user.'.$this->message->recever_id);
}
}
7.Мой код контроллера
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Message;
use App\Events\UserMessage;
class HomeController extends Controller{
public function __construct(){
$this->middleware('auth');
}
public function messageCreate(Request $request){
$request->validate([
'message' => 'required',
'recever_id' => 'required',
]);
$message = Message::create([
'user_id' => auth()->user()->id,
'recever_id' => $request->recever_id,
'message' => $request->message,
]);
if($message){
event(new UserMessage($message));
return ['status'=> true];
}
return ['status'=> false];
}
}
8.Мой код скрипта блейда
Echo.private('user.{{auth()->user()->id}}')
.listen('PrivateMessage', (e) => {
console.log(e);
});