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