48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Maintenance\Services;
|
|
|
|
use App\Business;
|
|
use App\User;
|
|
use App\Modules\Maintenance\Models\MaintenanceNotification;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class MaintenanceNotificationService
|
|
{
|
|
public static function notify(
|
|
Business $business,
|
|
User $user,
|
|
string $type,
|
|
string $title,
|
|
string $message,
|
|
?array $data = null,
|
|
array $channels = ['dashboard']
|
|
): MaintenanceNotification {
|
|
return MaintenanceNotification::create([
|
|
'business_id' => $business->id,
|
|
'user_id' => $user->id,
|
|
'type' => $type,
|
|
'title' => $title,
|
|
'message' => $message,
|
|
'data' => $data,
|
|
'channels' => $channels,
|
|
'sent_at' => now(),
|
|
]);
|
|
}
|
|
|
|
public static function unreadForUser(Business $business, User $user, int $limit = 20): Collection
|
|
{
|
|
return MaintenanceNotification::where('business_id', $business->id)
|
|
->where('user_id', $user->id)
|
|
->whereNull('read_at')
|
|
->orderByDesc('created_at')
|
|
->limit($limit)
|
|
->get();
|
|
}
|
|
|
|
public static function markRead(MaintenanceNotification $notification): void
|
|
{
|
|
$notification->update(['read_at' => now()]);
|
|
}
|
|
}
|