repository = $district; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Realestate\Place\Repositories\Criteria\DistrictResourceCriteria::class); } /** * Display a list of district. * * @return Response */ public function index(DistrictRequest $request) { if ($this->response->typeIs('json')) { $pageLimit = $request->input('pageLimit'); $data = $this->repository ->setPresenter(\Realestate\Place\Repositories\Presenter\DistrictListPresenter::class) ->getDataTable($pageLimit); return $this->response ->data($data) ->output(); } $districts = $this->repository->paginate(); return $this->response->title(trans('place::district.names')) ->view('place::district.index', true) ->data(compact('districts')) ->output(); } /** * Display district. * * @param Request $request * @param Model $district * * @return Response */ public function show(DistrictRequest $request, District $district) { if ($district->exists) { $view = 'place::district.show'; } else { $view = 'place::district.new'; } return $this->response->title(trans('app.view') . ' ' . trans('place::district.name')) ->data(compact('district')) ->view($view, true) ->output(); } /** * Show the form for creating a new district. * * @param Request $request * * @return Response */ public function create(DistrictRequest $request) { $district = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('place::district.name')) ->view('place::district.create', true) ->data(compact('district')) ->output(); } /** * Create new district. * * @param Request $request * * @return Response */ public function store(DistrictRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $district = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('place::district.name')])) ->code(204) ->status('success') ->url(guard_url('place/district/' . $district->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/place/district')) ->redirect(); } } /** * Show district for editing. * * @param Request $request * @param Model $district * * @return Response */ public function edit(DistrictRequest $request, District $district) { return $this->response->title(trans('app.edit') . ' ' . trans('place::district.name')) ->view('place::district.edit', true) ->data(compact('district')) ->output(); } /** * Update the district. * * @param Request $request * @param Model $district * * @return Response */ public function update(DistrictRequest $request, District $district) { try { $attributes = $request->all(); $district->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('place::district.name')])) ->code(204) ->status('success') ->url(guard_url('place/district/' . $district->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('place/district/' . $district->getRouteKey())) ->redirect(); } } /** * Remove the district. * * @param Model $district * * @return Response */ public function destroy(DistrictRequest $request, District $district) { try { $district->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('place::district.name')])) ->code(202) ->status('success') ->url(guard_url('place/district')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('place/district/' . $district->getRouteKey())) ->redirect(); } } /** * Remove multiple district. * * @param Model $district * * @return Response */ public function delete(DistrictRequest $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('place::district.name')])) ->status("success") ->code(202) ->url(guard_url('place/district')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/place/district')) ->redirect(); } } /** * Restore deleted districts. * * @param Model $district * * @return Response */ public function restore(DistrictRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('place::district.name')])) ->status("success") ->code(202) ->url(guard_url('/place/district')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/place/district/')) ->redirect(); } } }