orderByDesc('created_at') ->paginate(20); return view('notifications.index', compact('notifications')); } public function markAsRead(UserNotification $notification): \Illuminate\Http\RedirectResponse { $this->authorizeNotification($notification); $notification->markAsRead(); return back()->with('success', __('Notification marked as read.')); } public function markAllAsRead(): \Illuminate\Http\RedirectResponse { UserNotification::where('user_id', Auth::id()) ->where('is_read', false) ->update(['is_read' => true, 'read_at' => now()]); return back()->with('success', __('All notifications marked as read.')); } private function authorizeNotification(UserNotification $notification): void { if ($notification->user_id !== Auth::id()) { abort(403); } } }