form = ComercialForm::setAttributes()->toArray(); $this->modules = $this->modules(config('reinaldo.teste00pkg.modules'), 'teste00pkg', guard_url('teste00pkg')); $this->repository = $comercial; } /** * Display a list of comercial. * * @return Response */ public function index(ComercialRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(ComercialResourceFilter::class) ->setPresenter(ComercialListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('teste00pkg::comercial.names')) ->view('teste00pkg::comercial.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display comercial. * * @param Request $request * @param Model $comercial * * @return Response */ public function show(ComercialRequest $request, ComercialRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('teste00pkg::comercial.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('teste00pkg::comercial.show') ->output(); } /** * Show the form for creating a new comercial. * * @param Request $request *x * @return Response */ public function create(ComercialRequest $request, ComercialRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('teste00pkg::comercial.name')) ->view('teste00pkg::comercial.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new comercial. * * @param Request $request * * @return Response */ public function store(ComercialRequest $request, ComercialRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('teste00pkg::comercial.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('teste00pkg/comercial/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/teste00pkg/comercial')) ->redirect(); } } /** * Show comercial for editing. * * @param Request $request * @param Model $comercial * * @return Response */ public function edit(ComercialRequest $request, ComercialRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('teste00pkg::comercial.name')) ->view('teste00pkg::comercial.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the comercial. * * @param Request $request * @param Model $comercial * * @return Response */ public function update(ComercialRequest $request, ComercialRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('teste00pkg::comercial.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('teste00pkg/comercial/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('teste00pkg/comercial/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the comercial. * * @param Model $comercial * * @return Response */ public function destroy(ComercialRequest $request, ComercialRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('teste00pkg::comercial.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('teste00pkg/comercial/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('teste00pkg/comercial/' . $repository->getRouteKey())) ->redirect(); } } }