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