36 lines
803 B
PHP
36 lines
803 B
PHP
<?php
|
|
|
|
namespace App\Notifications\Channels;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
use App\Services\FCMService;
|
|
|
|
class FcmChannel
|
|
{
|
|
/**
|
|
* Send the given notification.
|
|
*
|
|
* @param mixed $notifiable
|
|
* @param \Illuminate\Notifications\Notification $notification
|
|
* @return void
|
|
*/
|
|
public function send($notifiable, Notification $notification)
|
|
{
|
|
if (!method_exists($notification, 'toFcm')) {
|
|
return;
|
|
}
|
|
|
|
$fcmData = $notification->toFcm($notifiable);
|
|
if (!$fcmData || empty($fcmData['token'])) {
|
|
return;
|
|
}
|
|
|
|
FCMService::sendPushNotification(
|
|
$fcmData['token'],
|
|
$fcmData['title'],
|
|
$fcmData['body'],
|
|
$fcmData['data'] ?? []
|
|
);
|
|
}
|
|
}
|