我正在尝试使用pusher进行通知,但是当我发出请求时,我没有看到任何错误,但是通知不起作用。
控制器:
public function requestCommunityMembership(Request $request, Community $community){
$user = $this->getAuthorizedUser($request->header('X-User-Auth-Token'));
//$user = User::find(6999);
if (!$user) {
return response()->json(['error' => true, 'code' => 401, 'message' => INVALID_AUTH_TOKEN], 401);
}
$data = [
'sender_id' => $user->id,
'type' => 'notification',
'type_id' => null,
'title' => null,
'receiver_id' => $community->user_id,
'message' => null,
'sent_at' => Carbon::now()->format('Y-m-d H:i:s'),
];
$app_notification = AppNotification::create($data);
event(new SendCommunityMembershipNotification($community));
return response()->json(['error' => false, 'code' => 200, 'message' => $app_notification], 200);
}
通知如下:
class SendCommunityMembershipNotification
{
use Dispatchable, InteractsWithSockets, SerializesModels;
protected $community;
public function __construct($community)
{
$this->community = $community;
}
public function broadcastAs()
{
return 'new-membership-request-event';
}
public function broadcastOn()
{
$channel = 'golfplayed-new-membership-request-' . $this->community->user_id;
return new Channel($channel);
}
}
我的broadcast.php看起来像这样:
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'usss',
'encrypted' => true
],
],
其余部分位于.env
PUSHER_APP_NAME=gnameed
PUSHER_APP_ID=XXXXX
PUSHER_APP_KEY=YYYYYY
PUSHER_APP_SECRET=ZZZZZZZZZ
PUSHER_APP_CLUSTER=usss
我还必须添加其他内容以使通知正常工作吗?
已更新:我刚刚用通知代码更新了问题