44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\NotificationService;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class NotificationController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
}
|
|
|
|
public function index(NotificationService $notifications)
|
|
{
|
|
return response()->json($notifications->inboxPayload(Auth::user()));
|
|
}
|
|
|
|
public function markAsRead(NotificationService $notifications, $id)
|
|
{
|
|
$notification = $notifications->markAsRead(Auth::user(), $id);
|
|
|
|
if (!$notification) {
|
|
return response()->json(['message' => 'Notifikasi tidak dijumpai.'], 404);
|
|
}
|
|
|
|
return response()->json([
|
|
'notification' => $notification->toInboxArray(),
|
|
'unread_count' => $notifications->unreadCount(Auth::user()),
|
|
]);
|
|
}
|
|
|
|
public function markAllAsRead(NotificationService $notifications)
|
|
{
|
|
$updated = $notifications->markAllAsRead(Auth::user());
|
|
|
|
return response()->json([
|
|
'updated' => $updated,
|
|
'unread_count' => 0,
|
|
]);
|
|
}
|
|
}
|