'notifications', 'title' => 'Уведомления', 'id' => 'notifications', 'header' => [ 'created_at' => 'Дата', 'type' => 'Тип', 'event' => 'Событие', 'message' => 'Сообщение', 'read_at' => 'Прочитано', ], 'searchFields' => [ 'message', ], 'ranges' => [], 'filters' => [], ]; public function index(Request $request) { session(['gp_notifications' => $request->query()]); $model = new UserNotification; $userId = $request->user()->id; $q = $model::query()->where('user_id', $userId); $this->data['filters']['type'] = [ 'title' => 'Тип', 'values' => UserNotification::TYPE_NAMES, ]; $this->data['filters']['event'] = [ 'title' => 'Событие', 'values' => UserNotification::EVENT_NAMES, ]; $this->createDateFilters($model, 'created_at'); $this->acceptFilters($q, $request); $this->acceptSearch($q, $request); $this->setSortAndOrderBy($model, $request); $this->applyStableSorting($q); $this->data['notifications'] = $q->paginate($this->data['per_page'])->withQueryString(); return view('notifications.index', $this->data); } public function markRead(Request $request, UserNotification $notification): JsonResponse { if ($notification->user_id !== $request->user()->id) { abort(403); } if (!$notification->isRead()) { $notification->update(['read_at' => now()]); } return response()->json([ 'ok' => true, 'unread' => UserNotification::query() ->where('user_id', $request->user()->id) ->whereNull('read_at') ->count(), ]); } public function unreadCount(Request $request): JsonResponse { return response()->json([ 'count' => UserNotification::query() ->where('user_id', $request->user()->id) ->whereNull('read_at') ->count(), ]); } }