PM_Console/backend/app/Services/NotificationService.php

26 خطوط
647 B
PHP

<?php
namespace App\Services;
use App\Models\Notification;
class NotificationService
{
public function create($userId, $type, $data, $message)
{
$payload = is_array($data) ? $data : null;
return Notification::create([
'user_id' => $userId,
'type' => $type,
'title' => $message,
'body' => is_array($data) ? null : $data,
'data' => $payload,
'notifiable_type' => $payload['notifiable_type'] ?? null,
'notifiable_id' => $payload['notifiable_id'] ?? null,
'is_read' => false,
'read_at' => null,
]);
}
}