update send notification fcm
This commit is contained in:
39
app/Notifications/SendNotification.php
Normal file
39
app/Notifications/SendNotification.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\Fcm\FcmChannel;
|
||||
use NotificationChannels\Fcm\FcmMessage;
|
||||
|
||||
class SendNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
private $title;
|
||||
private $body;
|
||||
private $data;
|
||||
|
||||
public function __construct($title, $body, $data)
|
||||
{
|
||||
$this->title = $title;
|
||||
$this->body = $body;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function via($notifiable)
|
||||
{
|
||||
return [FcmChannel::class];
|
||||
}
|
||||
|
||||
public function toFcm($notifiable)
|
||||
{
|
||||
return FcmMessage::create()
|
||||
->setData($this->data) // Menggunakan $this->data
|
||||
->setNotification([
|
||||
'title' => $this->title,
|
||||
'body' => $this->body,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user