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