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