I am trying to receive notification using echo + pusher. I can post to pusher and pusher console receive the event and channel but i can't get this data on laravel. I read many document none of work for me.
WebNotification Class // Notification file
private $subscription;
public function __construct($data)
{
$this->subscription = $data;
}
public function via($notifiable)
{
return ['database','broadcast'];
}
public function toBroadcast($notifiable)
{
return new BroadcastMessage([
'data' => $this->subscription,
'count' => $notifiable->unreadNotifications->count()
]);
}
Account Model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class account extends Model
{
use Notifiable;
public function receivesBroadcastNotificationsOn()
{
return 'accounts.'.$this->id;
}
}
MyNotification // To call event to send data to pusher
public function DatabaseNot(){
$user = Account::where('id', Cookie::get('uid'))->first();
$data = collect(['title'=>'Hello Title', 'body'=>'my body']);
$user->notify(new WebNotification($data));
return view('layout.test',['user'=>$user]);
}
Pusher log
Channel: private-accounts.23, Event: Illuminate\Notifications\Events\BroadcastNotificationCreated
I call Echo in resorces/js/app.js
Echo.private('App.accounts.23')
.notification((notification) => {
console.log(notification.type);
});
I was not get any response from this. I was already add csrf token in meta, I was compile js code using NPM run watch. I was try men others way no one provide clear document its so much confuse. Please provide me solution
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire