我想通过PHP套接字在控制器的某个通道上订阅Laravel广播的事件,所以我不想涉及任何前端库来进行通知。 这是我的channels.php代码
Broadcast::channel('user.{toUserId}', function ($user, $toUserId) {
return $user->id == $toUserId;
});
这里是我的TaskNotification.php代码
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->to);
}
我正在通过homeController @ index方法广播此事件,并希望订阅homeController @ other方法
public function index(){
event(new TaskNotification("my message"));
return view("welcome");
}
public function other(){
}