2017-11-12 1 views
-2

プッシャーを使用して、Laravelアプリに簡単なテスト通知をブロードキャストしようとしています。私のウェブページでは、このJavaScriptを取得してbootstrap.jsで ブロードキャストLaravel 5.3プッシュ通知がエコーで受信されない

0:
import Echo from 'laravel-echo' 

window.Echo = new Echo({ 
    broadcaster: 'pusher', 
    key: 'notmyrealpusherkey', 
    encrypted: true 
}); 

この

Echo.private('App.User.' + this.id) 
    .notification((notification) => { 
     console.log(notification); 
     toastr.info(notification.message, notification.subject); 
    }); 

マイBroadcastServiceProviderがプライベートチャネル要求を検証するように設定されて私のNotification.vueです

私はプッシャーコンソールをチェックすると、私はここで成功した加入チェック画像上のコードことがわかります。私はプッシャーから直接通知を送信すると https://d1ro8r1rbfn3jf.cloudfront.net/ms_76665/NvEB7BgUnmIA2IR5rO1S3gF1aSP306/Pusher%2B-%2BDebug%2Bconsole%2B2016-12-28%2B19-37-19.png?Expires=1510590716&Signature=Cgykr97sBJUqljH02DfUJztcILiFTMUsUBfsF4kXoYsuJCsHf4lG-3tyhXBmCM70rWGyeCqZ7nrkgqYuOYEYs6Q41nq-ActI9B-vt6fhh5rYgekfe-HM0dERY67OqAbaLVfskq2mUp1Zl7yBPKwgNR9Fw0uzdH8q6ia9L0Za9QBLM1u6Fq3AHoN4OodJaXr5X-ifn1ZVAC7WsYVtLcnWpr3Yx0-w2nzbS4rD2S9KtMnIpsOA8bcHHWW3qoDFm5J0hIB6GVF42-vQTUNo~4B1~L8XT41coOarsF~sTVsaWTYINX93BmpVpKUEDyoarbffEuUsf4sZO6Ee5fILK1wJOQ__&Key-Pair-Id=APKAJHEJJBIZWFB73RSA

それがトリガー使用して送信コンソールに送信ではなくなります説明に画像リンク: https://d1ro8r1rbfn3jf.cloudfront.net/ms_76665/kxgC93iHRWnMPHIdJehBgfsfUG47Lu/Pusher%2B-%2BDebug%2Bconsole%2B2016-12-28%2B19-37-56.png?Expires=1510592071&Signature=f8wvoKGnWLROJ0cXCWqkWz3EVL6rVj6PuJ~-gXpHHgrt7FlZ9gf9YO3lezW2dplmN08419w9qWJh-Cc7cpt4B1dEEwqORjL8eRz528B6l-HKHwnn96iCIE~bfwc80L9qJx9nBbLqTqnEkAlvbugcGlIrr1zB-iMlz9TMloLpYkq-2T-a1Ww8BM3SmbETVunLqhqYxUCbgK3T1swS135tqvg36sA8FWWnBe3djHgSTUuYS6Nv8MyvkF8JS1slxtMzsJ30oEzs5zc~QhEfECfoA8On8VIHP8a4VrOjUyElcrcPHG~7TwnYP8Ajje7O7EW9SNyIV7t3LSyxBGiIdsVDtQ__&Key-Pair-Id=APKAJHEJJBIZWFB73RSA

NewFriendRequestは単なるテスト通知です:

<?php 

namespace App\Notifications; 

use Illuminate\Bus\Queueable; 
use Illuminate\Notifications\Notification; 
use Illuminate\Contracts\Queue\ShouldQueue; 
use Illuminate\Notifications\Messages\MailMessage; 

class NewFriendRequest extends Notification implements ShouldQueue 
{ 
use Queueable; 

public $user; 

/** 
* Create a new notification instance. 
* 
* @return void 
*/ 
public function __construct($user) 
{ 
    $this->user = $user; 
} 

/** 
* Get the notification's delivery channels. 
* 
* @param mixed $notifiable 
* @return array 
*/ 
public function via($notifiable) 
{ 
    return ['mail','broadcast','database']; 
} 

/** 
* Get the mail representation of the notification. 
* 
* @param mixed $notifiable 
* @return \Illuminate\Notifications\Messages\MailMessage 
*/ 
public function toMail($notifiable) 
{ 
    return (new MailMessage) 
       ->line('You received a new friend request from ' . $this->user->name) 
       ->action('View Profile', route('profile', ['slug' => $this->user->slug])) 
       ->line('Thank you for using our Tictac!'); 
} 

/** 
* Get the array representation of the notification. 
* 
* @param mixed $notifiable 
* @return array 
*/ 
public function toArray($notifiable) 
{ 
    return [ 
     'name' => $this->user->name, 
     'message' => $this->user->name . ' sent you friend request.' 
    ]; 
} 


    } 

私はまた、Laravel側からそれをトリガーしようとしたが、それはまだ、ユーザーのブラウザに到達していない:

$resp = Auth::user()->add_friend($id); 
User::find($id)->notify(new \App\Notifications\NewFriendRequest(Auth::user())); 
return $resp; 
+0

引用符を削除し、コードを適切にフォーマットしてください。読むのは難しいです。また、リンクが壊れています。 – Jeffrey

+0

私は自分のコードを編集plz参照してください。私は疲れているので、私はこの賛成論に直面している.. –

+0

プッシャーのコンソールにあなたのイベント(クライアントのサブスクリプションではない)が届いていますか? – Jeffrey

答えて

0

あなたの通知、as stated by the documentationtoBroadcast()方法を逃しています。

class NewFriendRequest extends Notification implements ShouldQueue 
{ 
    public function toBroadcast($notifiable) 
    { 
     return new BroadcastMessage([ 
      'message' => 'Insert your message', 
      'subject' => 'Insert your subject', 
     ]); 
    } 
} 
+0

iはコンソール –

+0

パブリック関数のtoArray($届出) { リターン[ '名称' =>の$ this - > USER->名、 'メッセージ' =>の$ this - で放送データを返すためのtoArray関数を使用有します> user-> name。 'あなたに友人のリクエストを送りました。' ]; } –

+0

私はあなたのコードを使用してpap artisanキューを実行すると、laravel 5.5、pusher 3.0 –

関連する問題