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