store/app/Services/System/PushNotificationService.php

35 lines
924 B
PHP

<?php
namespace App\Services\System;
use App\Jobs\SendPushNotificationJob;
class PushNotificationService
{
/**
* Send notification to users with specific roles.
*
* @param list<string> $roles
*/
public function sendToRoles(string $title, string $body, array $roles, string $url = '/admin/dashboard'): void
{
SendPushNotificationJob::dispatch($title, $body, $url, $roles);
}
/**
* Send notification to a specific user.
*/
public function sendToUser(string $title, string $body, int $userId, string $url = '/admin/dashboard'): void
{
SendPushNotificationJob::dispatch($title, $body, $url, [], $userId);
}
/**
* Send notification to all users.
*/
public function sendToAll(string $title, string $body, string $url = '/admin/dashboard'): void
{
SendPushNotificationJob::dispatch($title, $body, $url, []);
}
}