repository = $features; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\Feature\Repositories\Criteria\FeaturesResourceCriteria::class); } /** * Display a list of features. * * @return Response */ public function index(FeaturesRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Litecms\Feature\Repositories\Presenter\FeaturesPresenter::class) ->$function(); } $features = $this->repository->paginate(); return $this->response->title(trans('feature::features.names')) ->view('feature::features.index', true) ->data(compact('features')) ->output(); } /** * Display features. * * @param Request $request * @param Model $features * * @return Response */ public function show(FeaturesRequest $request, Features $features) { if ($features->exists) { $view = 'feature::features.show'; } else { $view = 'feature::features.new'; } return $this->response->title(trans('app.view') . ' ' . trans('feature::features.name')) ->data(compact('features')) ->view($view, true) ->output(); } /** * Show the form for creating a new features. * * @param Request $request * * @return Response */ public function create(FeaturesRequest $request) { $features = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('feature::features.name')) ->view('feature::features.create', true) ->data(compact('features')) ->output(); } /** * Create new features. * * @param Request $request * * @return Response */ public function store(FeaturesRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $features = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('feature::features.name')])) ->code(204) ->status('success') ->url(guard_url('feature/features/' . $features->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/feature/features')) ->redirect(); } } /** * Show features for editing. * * @param Request $request * @param Model $features * * @return Response */ public function edit(FeaturesRequest $request, Features $features) { return $this->response->title(trans('app.edit') . ' ' . trans('feature::features.name')) ->view('feature::features.edit', true) ->data(compact('features')) ->output(); } /** * Update the features. * * @param Request $request * @param Model $features * * @return Response */ public function update(FeaturesRequest $request, Features $features) { try { $attributes = $request->all(); $features->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('feature::features.name')])) ->code(204) ->status('success') ->url(guard_url('feature/features/' . $features->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('feature/features/' . $features->getRouteKey())) ->redirect(); } } /** * Remove the features. * * @param Model $features * * @return Response */ public function destroy(FeaturesRequest $request, Features $features) { try { $features->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('feature::features.name')])) ->code(202) ->status('success') ->url(guard_url('feature/features/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('feature/features/' . $features->getRouteKey())) ->redirect(); } } /** * Remove multiple features. * * @param Model $features * * @return Response */ public function delete(FeaturesRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('feature::features.name')])) ->status("success") ->code(202) ->url(guard_url('feature/features')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/feature/features')) ->redirect(); } } /** * Restore deleted features. * * @param Model $features * * @return Response */ public function restore(FeaturesRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('feature::features.name')])) ->status("success") ->code(202) ->url(guard_url('/feature/features')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/feature/features/')) ->redirect(); } } }