form = UserForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('litecms.lead.modules'), 'lead', guard_url('lead')); } /** * Display a list of user. * * @return Response */ public function index(UserResourceRequest $request) { $request = $request->all(); $page = UserActions::run('paginate', $request); $data = new UsersCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('lead::user.names')) ->view('lead::user.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display user. * * @param Request $request * @param Model $user * * @return Response */ public function show(UserResourceRequest $request, User $model) { $form = $this->form; $modules = $this->modules; $data = new UserResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('lead::user.name')) ->data(compact('data', 'form', 'modules')) ->view('lead::user.show') ->output(); } /** * Show the form for creating a new user. * * @param Request $request * * @return Response */ public function create(UserResourceRequest $request, User $model) { $form = $this->form; $modules = $this->modules; $data = new UserResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('lead::user.name')) ->view('lead::user.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new user. * * @param Request $request * * @return Response */ public function store(UserResourceRequest $request, User $model) { try { $request = $request->all(); $model = UserAction::run('store', $model, $request); $data = new UserResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('lead::user.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('lead/user/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/lead/user')) ->redirect(); } } /** * Show user for editing. * * @param Request $request * @param Model $user * * @return Response */ public function edit(UserResourceRequest $request, User $model) { $form = $this->form; $modules = $this->modules; $data = new UserResource($model); // return view('lead::user.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('lead::user.name')) ->view('lead::user.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the user. * * @param Request $request * @param Model $user * * @return Response */ public function update(UserResourceRequest $request, User $model) { try { $request = $request->all(); $model = UserAction::run('update', $model, $request); $data = new UserResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('lead::user.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('lead/user/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('lead/user/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the user. * * @param Model $user * * @return Response */ public function destroy(UserResourceRequest $request, User $model) { try { $request = $request->all(); $model = UserAction::run('destroy', $model, $request); $data = new UserResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('lead::user.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('lead/user/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('lead/user/' . $model->getRouteKey())) ->redirect(); } } }