middleware(function ($request, $next) { $this->form = UserForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('litepie.team.modules'), 'team', guard_url('team')); return $next($request); }); } /** * 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('team::user.names')) ->view('team::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('team::user.name')) ->data(compact('data', 'form', 'modules')) ->view('team::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('team::user.name')) ->view('team::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('team::user.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('team/user/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/team/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('team::user.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('team::user.name')) ->view('team::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('team::user.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('team/user/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('team/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('team::user.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('team/user/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('team/user/' . $model->getRouteKey())) ->redirect(); } } }