public function index() { $user = \Authorization::user(); $options = new QueryFilter(); $options->set('only', \Input::get('only'), ''); $options->set('except', \Input::get('except'), ''); $options->set('after', \Input::get('after'), null, $this->notificationRepository); $options->set('before', \Input::get('before'), null, $this->notificationRepository); $options->set('take', (int) \Input::get('take'), 90, null, [1, 90]); $options->set('split', \Input::get('split'), false); if (\Input::exists('count')) { $count = $this->notificationService->getNumberOfUnreadNotifications($user); return ['count' => $count]; } if (\Input::exists('unread')) { $notifications = $this->notificationService->getUnreadUserNotifications($user, $options); } else { $notifications = $this->notificationService->getUserNotifications($user, $options); } if (count($notifications) == 0) { return $this->withCollection([], new NotificationTransformer(), 'notifications'); } return $this->withCollection($notifications, new NotificationTransformer(), 'notifications'); }
protected function appendLimitingOptions($q, QueryFilter $filter) { $q = $q->take($filter->get('take')); if ($after = $filter->get('after')) { $q = $q->where('id', '>', $after->id); } if ($before = $filter->get('before')) { $q = $q->where('id', '<', $before->id); } if ($only = $filter->get('only')) { $onlyFilter = new Collection(explode(',', $only)); $q = $q->whereIn('notification_type', $onlyFilter->toArray()); } if ($except = $filter->get('except')) { $exceptFilter = new Collection(explode(',', $except)); $q = $q->whereNotIn('notification_type', $exceptFilter->toArray()); } return $q; }