feat: tambah database notifications dan widget activity log di dashboard
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\User;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class NotificationService
|
||||
{
|
||||
public static function send(User|iterable $recipients, string $title, string $body, string $color = 'info', ?string $url = null): void
|
||||
{
|
||||
$notification = Notification::make()
|
||||
->title($title)
|
||||
->body($body)
|
||||
->color($color);
|
||||
|
||||
if ($url) {
|
||||
$notification->actions([
|
||||
\Filament\Notifications\Actions\Action::make('lihat')
|
||||
->label('Lihat')
|
||||
->url($url),
|
||||
]);
|
||||
}
|
||||
|
||||
$notification->sendToDatabase(
|
||||
$recipients instanceof User ? collect([$recipients]) : collect($recipients)
|
||||
);
|
||||
}
|
||||
|
||||
public static function toRole(string $role, string $title, string $body, string $color = 'info', ?string $url = null): void
|
||||
{
|
||||
$users = User::role($role)->get();
|
||||
if ($users->isEmpty()) return;
|
||||
self::send($users, $title, $body, $color, $url);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user