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