middleware(function ($request, $next) { $this->form = FeatureForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('classifieds.feature.modules'), 'feature', guard_url('feature')); return $next($request); }); } /** * Display a list of feature. * * @return Response */ public function index(FeatureResourceRequest $request) { $request = $request->all(); $page = FeatureActions::run('paginate', $request); $data = new FeaturesCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('feature::feature.names')) ->view('feature::feature.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display feature. * * @param Request $request * @param Model $feature * * @return Response */ public function show(FeatureResourceRequest $request, Feature $model) { $form = $this->form; $modules = $this->modules; $data = new FeatureResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('feature::feature.name')) ->data(compact('data', 'form', 'modules')) ->view('feature::feature.show') ->output(); } /** * Show the form for creating a new feature. * * @param Request $request * * @return Response */ public function create(FeatureResourceRequest $request, Feature $model) { $form = $this->form; $modules = $this->modules; $data = new FeatureResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('feature::feature.name')) ->view('feature::feature.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new feature. * * @param Request $request * * @return Response */ public function store(FeatureResourceRequest $request, Feature $model) { try { $request = $request->all(); $model = FeatureAction::run('store', $model, $request); $data = new FeatureResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('feature::feature.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('feature/feature/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/feature/feature')) ->redirect(); } } /** * Show feature for editing. * * @param Request $request * @param Model $feature * * @return Response */ public function edit(FeatureResourceRequest $request, Feature $model) { $form = $this->form; $modules = $this->modules; $data = new FeatureResource($model); // return view('feature::feature.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('feature::feature.name')) ->view('feature::feature.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the feature. * * @param Request $request * @param Model $feature * * @return Response */ public function update(FeatureResourceRequest $request, Feature $model) { try { $request = $request->all(); $model = FeatureAction::run('update', $model, $request); $data = new FeatureResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('feature::feature.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('feature/feature/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('feature/feature/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the feature. * * @param Model $feature * * @return Response */ public function destroy(FeatureResourceRequest $request, Feature $model) { try { $request = $request->all(); $model = FeatureAction::run('destroy', $model, $request); $data = new FeatureResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('feature::feature.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('feature/feature/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('feature/feature/' . $model->getRouteKey())) ->redirect(); } } }