user()->notifications; return view('notification.index', $data); } public function markAsRead(Request $request) { $filterData = $request->all(); try { $notification = auth()->user()->notifications()->where('id', $filterData['id'])->first(); if ($notification) { $notification->markAsRead(); } return redirect()->back()->withSuccess('Mark As Read'); } catch (\Throwable $th) { return redirect()->back()->withError('Something Went Wrong!'); } } public function markAllAsRead(Request $request) { try { foreach (auth()->user()->unreadNotifications as $notification) { $notification->markAsRead(); } return redirect()->back()->withSuccess('Mark All As Read'); } catch (\Throwable $th) { //throw $th; return redirect()->back()->withError('Something Went Wrong!'); } } }