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