check()) { $components = Component::query(); } else { $components = Component::enabled(); } if ($tags = Binput::get('tags')) { $components->withAnyTags($tags); } $components->search(Binput::except(['sort', 'order', 'per_page'])); if ($sortBy = Binput::get('sort')) { $direction = Binput::has('order') && Binput::get('order') == 'desc'; $components->sort($sortBy, $direction); } $components = $components->paginate(Binput::get('per_page', 20)); return $this->paginator($components, Request::instance()); } /** * Get a single component. * * @param \CachetHQ\Cachet\Models\Component $component * * @return \Illuminate\Http\JsonResponse */ public function show(Component $component) { return $this->item($component); } /** * Create a new component. * * @return \Illuminate\Http\JsonResponse */ public function store() { try { $component = execute(new CreateComponentCommand( Binput::get('name'), Binput::get('description'), Binput::get('status'), Binput::get('link'), Binput::get('order'), Binput::get('group_id'), (bool) Binput::get('enabled', true), Binput::get('meta'), Binput::get('tags') )); } catch (QueryException $e) { throw new BadRequestHttpException(); } return $this->item($component); } /** * Update an existing component. * * @param \CachetHQ\Cachet\Models\Component $component * * @return \Illuminate\Http\JsonResponse */ public function update(Component $component) { try { execute(new UpdateComponentCommand( $component, Binput::get('name'), Binput::get('description'), Binput::get('status'), Binput::get('link'), Binput::get('order'), Binput::get('group_id'), Binput::get('enabled', $component->enabled), Binput::get('meta'), Binput::get('tags'), (bool) Binput::get('silent', false) )); } catch (QueryException $e) { throw new BadRequestHttpException(); } return $this->item($component); } /** * Delete an existing component. * * @param \CachetHQ\Cachet\Models\Component $component * * @return \Illuminate\Http\JsonResponse */ public function destroy(Component $component) { execute(new RemoveComponentCommand($component)); return $this->noContent(); } }