38 lines
914 B
PHP
38 lines
914 B
PHP
<?php
|
|
|
|
namespace App\Notifications\Channels;
|
|
|
|
use App\Models\User;
|
|
use App\Services\Push\PushDriver;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class PushChannel
|
|
{
|
|
public function __construct(private readonly PushDriver $driver) {}
|
|
|
|
public function send(mixed $notifiable, Notification $notification): void
|
|
{
|
|
if (! $notifiable instanceof User) {
|
|
return;
|
|
}
|
|
if (! $notifiable->fcm_token) {
|
|
return;
|
|
}
|
|
if (! method_exists($notification, 'toPush')) {
|
|
return;
|
|
}
|
|
|
|
$payload = $notification->toPush($notifiable);
|
|
if (empty($payload['title']) || empty($payload['body'])) {
|
|
return;
|
|
}
|
|
|
|
$this->driver->send(
|
|
token: $notifiable->fcm_token,
|
|
title: $payload['title'],
|
|
body: $payload['body'],
|
|
data: $payload['data'] ?? [],
|
|
);
|
|
}
|
|
}
|