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