コード例 #1
0
ファイル: UsersController.php プロジェクト: alkindi91/DARES
 /**
  * Create a new user with data sent from the create form
  * @param  CreateUserRequest $request we validate the data sent from the form in this class before we continue our logic
  * @return \Illuminate\Support\Facades\Redirect redirect the user to the users index view
  */
 public function store(CreateUserRequest $request, User $UserModel)
 {
     // fill the model with the sent from the form
     $UserModel->fill($request->all());
     // add the password after encrypting it
     $UserModel->password = bcrypt($request->input('password'));
     // save the user
     $UserModel->save();
     // we process the user permissions based on the new ones sent from the view
     $this->processPermissions($UserModel);
     // the message that will be sent back to the user
     $message = trans('users::users.create_success', ['name' => $UserModel->name]);
     // redirect back to the users index
     if (request('submit') == 'save') {
         return redirect()->back()->with('success', $message);
     }
     return redirect()->route('users.index')->with('success', $message);
 }
コード例 #2
0
 /**
  *
  * @param CreateUserRequest $request
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 public function store(CreateUserRequest $request, UserEntity $entity)
 {
     DB::beginTransaction();
     try {
         $user = User::create($request->all());
         if ($request->has('roles')) {
             $user->roles()->sync($request->get('roles'));
         } else {
             $user->roles()->sync([]);
         }
         $this->updateEntry($entity->getEntity()->id, $user->id, ['input' => $request->all()]);
         DB::commit();
         SweetAlert::success('Se ha creado el Usuario', 'Excelente!')->autoclose(3500);
     } catch (EntryValidationException $e) {
         DB::rollBack();
         return back()->withInput($request->all())->withErrors($e->getErrors());
     }
     return redirect()->route('users.index');
 }