user(); $unread = $user->notifications() ->whereNull('read_at') ->latest() ->get(); if ($unread->isNotEmpty()) { return response()->json($unread); } $recent = $user->notifications() ->latest() ->limit(10) ->get(); return response()->json($recent); } public function markRead(Request $request, Notification $notification) { $this->authorize('update', $notification); $notification->markAsRead(); } }