66 lines
1.5 KiB
PHP
66 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Notifications\Notification;
|
|
use App\Notifications\Channels\FcmChannel;
|
|
|
|
class GenericNotification extends Notification
|
|
{
|
|
use Queueable;
|
|
|
|
public $title;
|
|
public $body;
|
|
public $data;
|
|
|
|
/**
|
|
* Create a new notification instance.
|
|
*/
|
|
public function __construct($title, $body, array $data = [])
|
|
{
|
|
$this->title = $title;
|
|
$this->body = $body;
|
|
$this->data = $data;
|
|
}
|
|
|
|
/**
|
|
* Get the notification's delivery channels.
|
|
*/
|
|
public function via($notifiable): array
|
|
{
|
|
$channels = ['database'];
|
|
if (!empty($notifiable->fcm_token)) {
|
|
$channels[] = FcmChannel::class;
|
|
}
|
|
return $channels;
|
|
}
|
|
|
|
/**
|
|
* Get the array representation of the notification for in-app database storage.
|
|
*/
|
|
public function toArray($notifiable): array
|
|
{
|
|
return array_merge([
|
|
'title' => $this->title,
|
|
'body' => $this->body,
|
|
], $this->data);
|
|
}
|
|
|
|
/**
|
|
* Get the push notification representation.
|
|
*/
|
|
public function toFcm($notifiable): array
|
|
{
|
|
return [
|
|
'token' => $notifiable->fcm_token,
|
|
'title' => $this->title,
|
|
'body' => $this->body,
|
|
'data' => array_merge([
|
|
'title' => $this->title,
|
|
'body' => $this->body,
|
|
], $this->data),
|
|
];
|
|
}
|
|
}
|