repository = $region; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Cenos\Master\Repositories\Criteria\RegionResourceCriteria::class); } /** * Display a list of region. * * @return Response */ public function index(RegionRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Cenos\Master\Repositories\Presenter\RegionPresenter::class) ->$function(); } $regions = $this->repository->paginate(); return $this->response->setMetaTitle(trans('master::region.names')) ->view('master::region.index', true) ->data(compact('regions', 'view')) ->output(); } /** * Display region. * * @param Request $request * @param Model $region * * @return Response */ public function show(RegionRequest $request, Region $region) { if ($region->exists) { $view = 'master::region.show'; } else { $view = 'master::region.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('master::region.name')) ->data(compact('region')) ->view($view, true) ->output(); } /** * Show the form for creating a new region. * * @param Request $request * * @return Response */ public function create(RegionRequest $request) { $region = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('master::region.name')) ->view('master::region.create', true) ->data(compact('region')) ->output(); } /** * Create new region. * * @param Request $request * * @return Response */ public function store(RegionRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $region = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('master::region.name')])) ->code(204) ->status('success') ->url(guard_url('master/region/' . $region->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/master/region')) ->redirect(); } } /** * Show region for editing. * * @param Request $request * @param Model $region * * @return Response */ public function edit(RegionRequest $request, Region $region) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('master::region.name')) ->view('master::region.edit', true) ->data(compact('region')) ->output(); } /** * Update the region. * * @param Request $request * @param Model $region * * @return Response */ public function update(RegionRequest $request, Region $region) { try { $attributes = $request->all(); $region->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('master::region.name')])) ->code(204) ->status('success') ->url(guard_url('master/region/' . $region->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('master/region/' . $region->getRouteKey())) ->redirect(); } } /** * Remove the region. * * @param Model $region * * @return Response */ public function destroy(RegionRequest $request, Region $region) { try { $region->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('master::region.name')])) ->code(202) ->status('success') ->url(guard_url('master/region/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('master/region/' . $region->getRouteKey())) ->redirect(); } } /** * Remove multiple region. * * @param Model $region * * @return Response */ public function delete(RegionRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('master::region.name')])) ->status("success") ->code(202) ->url(guard_url('master/region')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/master/region')) ->redirect(); } } /** * Restore deleted regions. * * @param Model $region * * @return Response */ public function restore(RegionRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('master::region.name')])) ->status("success") ->code(202) ->url(guard_url('/master/region')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/master/region/')) ->redirect(); } } }