form = NameForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('litecms.aml.modules'), 'aml', guard_url('aml')); } /** * Display a list of name. * * @return Response */ public function index(NameResourceRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $page = Name::pushScope(new RequestScope()) ->pushScope(new NameResourceScope()) ->paginate($pageLimit); $data = new NamesCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('aml::name.names')) ->view('aml::name.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display name. * * @param Request $request * @param Model $name * * @return Response */ public function show(NameResourceRequest $request, Name $model) { $form = $this->form; $modules = $this->modules; $data = new NameResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('aml::name.name')) ->data(compact('data', 'form', 'modules')) ->view('aml::name.show') ->output(); } /** * Show the form for creating a new name. * * @param Request $request * * @return Response */ public function create(NameResourceRequest $request, Name $model) { $form = $this->form; $modules = $this->modules; $data = new NameResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('aml::name.name')) ->view('aml::name.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new name. * * @param Request $request * * @return Response */ public function store(NameResourceRequest $request, Name $model) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $model = $model->create($attributes); $data = new NameResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('aml::name.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('aml/name/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/aml/name')) ->redirect(); } } /** * Show name for editing. * * @param Request $request * @param Model $name * * @return Response */ public function edit(NameResourceRequest $request, Name $model) { $form = $this->form; $modules = $this->modules; $data = new NameResource($model); // return view('aml::name.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('aml::name.name')) ->view('aml::name.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the name. * * @param Request $request * @param Model $name * * @return Response */ public function update(NameResourceRequest $request, Name $model) { try { $attributes = $request->all(); $model->update($attributes); $data = new NameResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('aml::name.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('aml/name/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('aml/name/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the name. * * @param Model $name * * @return Response */ public function destroy(NameResourceRequest $request, Name $model) { try { $model->delete(); $data = new NameResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('aml::name.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('aml/name/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('aml/name/' . $model->getRouteKey())) ->redirect(); } } }