前提・実現したいこと
laravelの通知機能とpusherを使ってリアルタイムに通知を受信したいのですが、クライアント側で受け取ることができずにいます。
なお、pusherのデバックコンソールでは通知の内容が表示されているので、laravel→pusher間は正常に動いているものと考えています。
発生している問題・エラーメッセージ
エラーは特に表示されていません。
該当のソースコード
コントローラ(MessageController.php)
php
1$organizer->notify(new RealtimeNoticeUpdated($organizer, $project, $postUser));
Notification(RealtimeNoticeUpdated.php)
php
1<?php 2 3namespace App\Notifications; 4 5use Illuminate\Bus\Queueable; 6use Illuminate\Contracts\Queue\ShouldQueue; 7use Illuminate\Notifications\Messages\MailMessage; 8use Illuminate\Notifications\Notification; 9use Illuminate\Notifications\Messages\BroadcastMessage; 10 11 12class RealtimeNoticeUpdated extends Notification implements ShouldQueue 13{ 14 use Queueable; 15 16 17 public $organizer; 18 public $project; 19 public $postUser; 20 21 public function __construct($organizer, $project, $postUser) 22 { 23 $this->organizer = $organizer; 24 $this->project = $project; 25 $this->postUser = $postUser; 26 } 27 28 public function via($notifiable) 29 { 30 return ['broadcast']; 31 } 32 33 public function toBroadcast($notifiable) 34 { 35 return new BroadcastMessage([ 36 'organizer_id' => $this->organizer->id, 37 'organizer_name' => $this->organizer->name, 38 'project_id' => $this->project->id, 39 'project_place' => $this->project->place, 40 'postUser_id' => $this->postUser->id, 41 'postUser_name' => $this->postUser->name, 42 ]); 43 } 44}
vueコンポーネント
vue
1//this.currentUserにはユーザーidが入っています(console.logにて確認済み) 2window.Echo.private('App.User.' + this.currentUser) 3 .notification((notification) => { 4 console.log(notification.type); 5 });
BroadcastServiceProvider.php
php
1<?php 2 3namespace App\Providers; 4 5use Illuminate\Support\Facades\Broadcast; 6use Illuminate\Support\ServiceProvider; 7 8class BroadcastServiceProvider extends ServiceProvider 9{ 10 /** 11 * Bootstrap any application services. 12 * 13 * @return void 14 */ 15 public function boot() 16 { 17 Broadcast::routes(['middleware' => ['auth:api']]); 18 19 require base_path('routes/channels.php'); 20 } 21}
pusherのデバックコンソールには情報が送られています。
(Socket IDが表示されないのが気になっております)
しかし、chromeのコンソールには何も情報が表示されません。
参考
公式ドキュメントを参考にしました。
Laravel 7.x 通知
補足情報(FW/ツールのバージョンなど)
Laravelのバージョンは7です。
開発はdockerデスクトップ上のphpコンテナで開発を行っており、動作検証はchrome(シークレットではない)とfirefoxを用いて実施しております。
chrome側で通知処理が発生するアクションを実施
↓
firefox側のコンソールでnotification.type
が表示されるか確認(←こちらが表示されずに悩んでいます)
firefox、chromeを逆にし試しましたが、同様に確認出来ませんでした。
なお、こちらのアプリケーション内でリアルタイムチャット機能をイベントブロードキャストとpusherを用いて実装しており、こちらは問題なくクライアント側で情報を受け取れているので、ブロードキャストの設定も問題ないと予想しております。
laravelのブロードキャスト通知機能特有の設定が必要なのでしょうか。
併せて、以下の記事を参考にブロードキャスト通知をメール通知の処理に置き換えてみた所、通知処理が発生するアクション実施したタイミングでメールが送られてきました。ですので、通知処理自体は動いているようです。
https://qiita.com/shimaji/items/8a89fc57bd3c73a24c32
ここ数日調べてみたのですが、解決に辿りつかず困っています。
質問内容に不足や不備等がございましたら修正いたしますので、アドバイスのほどよろしくお願いします。
あなたの回答
tips
プレビュー