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