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