当前位置: 首页>>代码示例>>PHP>>正文


PHP User::roles方法代码示例

本文整理汇总了PHP中app\models\User::roles方法的典型用法代码示例。如果您正苦于以下问题:PHP User::roles方法的具体用法?PHP User::roles怎么用?PHP User::roles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\User的用法示例。


在下文中一共展示了User::roles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updateManager

 /**
  * 更新管理型用户
  *
  * @param  App\Models\User $manager
  * @param  array $inputs
  * @return void
  */
 private function updateManager($manager, $inputs)
 {
     $manager->nickname = e($inputs['nickname']);
     $manager->realname = e($inputs['realname']);
     $manager->is_lock = e($inputs['is_lock']);
     if (!empty($inputs['password']) && !empty($inputs['password_confirmation'])) {
         $manager->password = bcrypt(e($inputs['password']));
     }
     if ($manager->save()) {
         //确保一个管理型用户只拥有一个角色
         $roles = $manager->roles;
         if ($roles->isEmpty()) {
             //判断角色结果集是否为空
             $manager->roles()->attach($inputs['role']);
             //空角色,则直接同步角色
         } else {
             if (is_array($roles)) {
                 //如果为对象数组,则表明该管理用户拥有多个角色
                 //则删除多个角色,再同步新的角色
                 $manager->detachRoles($roles);
                 $manager->roles()->attach($inputs['role']);
                 //同步角色
             } else {
                 if ($roles->first()->id !== $inputs['role']) {
                     $manager->detachRole($roles->first());
                     $manager->roles()->attach($inputs['role']);
                     //同步角色
                 }
             }
         }
         //上面这一大段代码就是保证一个管理型用户只拥有一个角色
         //Entrust扩展包自身是支持一个用户拥有多个角色的,但在本内容管理框架系统中,限定一个用户只能拥有一个角色
     }
 }
开发者ID:Zachary-Leung,项目名称:wine_platform,代码行数:41,代码来源:UserRepository.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //
     $person = new User();
     $person->first_name = $request->input('first-name');
     $person->last_name = $request->input('last-name');
     $person->email = $request->input('work-email');
     $person->personal_email = $request->input('personal-email');
     $person->password = Hash::make(uniqid());
     $person->address1 = $request->input('address-one');
     $person->address2 = $request->input('address-two');
     $person->zip = $request->input('postcode');
     $person->city = $request->input('city');
     $person->state = $request->input('state');
     $person->country = $request->input('country');
     $person->dob = Carbon::createFromFormat('d/m/Y', $request->input('dob'))->toDateString();
     $person->work_telephone = $request->input('work-telephone');
     $person->personal_telephone = $request->input('personal-telephone');
     $person->gender = $request->input('gender');
     $person->save();
     // Placeholder face until one is submitted
     $path = 'people/' . $person->id . '/face.jpg';
     \Illuminate\Support\Facades\Storage::put($path, file_get_contents('http://api.adorable.io/avatar/400/' . md5($person->id . $person->email . Carbon::now()->getTimestamp()) . ''));
     $person->save();
     // Default job position
     $person->jobPositions()->attach(1, ['primary' => true]);
     // Default role
     $person->roles()->attach(1, ['primary' => true]);
     return redirect()->intended('/people/');
 }
开发者ID:TeenageHelpline,项目名称:Progress,代码行数:36,代码来源:UserController.php

示例3: update

 public function update(User $user, UserRequest $request)
 {
     $user->update($request->all());
     $user->roles()->sync($request->input('roleList'));
     Flash::success(trans('general.updated_msg'));
     return redirect(route('admin.users'));
 }
开发者ID:AlexYaroma,项目名称:mightyducks,代码行数:7,代码来源:UsersController.php

示例4: setupFoundorAndBaseRolsPermission

 public function setupFoundorAndBaseRolsPermission()
 {
     // Create Roles
     $founder = new Role();
     $founder->name = 'Founder';
     $founder->save();
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     // Create User
     $user = new User();
     $user->username = 'admin';
     $user->display_name = 'Admin';
     $user->email = 'admin@local.com';
     $user->password = 'admin';
     if (!$user->save()) {
         Log::info('Unable to create user ' . $user->username, (array) $user->errors());
     } else {
         Log::info('Created user "' . $user->username . '" <' . $user->email . '>');
     }
     // Attach Roles to user
     $user->roles()->attach($founder->id);
     // Create Permissions
     $manageContent = new Permission();
     $manageContent->name = 'manage_contents';
     $manageContent->display_name = 'Manage Content';
     $manageContent->save();
     $manageUsers = new Permission();
     $manageUsers->name = 'manage_users';
     $manageUsers->display_name = 'Manage Users';
     $manageUsers->save();
     // Assign Permission to Role
     $founder->perms()->sync([$manageContent->id, $manageUsers->id]);
     $admin->perms()->sync([$manageContent->id]);
 }
开发者ID:axex,项目名称:kratos,代码行数:35,代码来源:2016_01_25_135943_entrust_setup_tables.php

示例5: signUp

 /**
  * Register a user
  *
  * @param  Request  $request
  * @return Response
  */
 public function signUp(Request $request)
 {
     if (intval(getenv('APP_PHASE')) < 2) {
         return ['error' => 'applications are not open'];
     }
     $validator = Validator::make($request->all(), ['first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email|unique:users', 'password' => 'required']);
     if ($validator->fails()) {
         return $validator->errors()->all();
     } else {
         $user = new User();
         $user->first_name = $request['first_name'];
         $user->last_name = $request['last_name'];
         $user->password = Hash::make($request['password']);
         $user->email = $request['email'];
         $user->save();
         $user->postSignupActions();
         // Attach roles
         $roles = $user->roles()->get()->lists('name');
         $token = JWTAuth::fromUser($user, ['exp' => strtotime('+1 year'), 'roles' => $roles, 'slug' => $user->slug()]);
         Mail::send('emails.welcome', ['user' => $user], function ($message) use($user) {
             $message->from('hello@boilermake.org', 'Laravel');
             $message->to($user->email);
         });
         return compact('token');
     }
 }
开发者ID:BoilerMake,项目名称:backend,代码行数:32,代码来源:AuthController.php

示例6: handle

 /**
  * Execute the job.
  * @return String
  * @internal param Role $role
  */
 public function handle()
 {
     $this->user->update($this->data->except('newsletter')->toArray());
     $this->user->setAttribute('newsletter', filter_var($this->data->get('newsletter', false), FILTER_VALIDATE_BOOLEAN));
     foreach ($this->association as $key => $value) {
         if ($value != '') {
             if ($key == 'role_id') {
                 $this->user->roles()->sync(array($value));
             } else {
                 $this->user->setAttribute($key, $value);
             }
         }
     }
     $this->user->save();
     event(new UserWasUpdated($this->user));
     return $this->user;
 }
开发者ID:SkysoulDesign,项目名称:mirage.dev,代码行数:22,代码来源:UpdateUserJob.php

示例7: doAdd

 public function doAdd(Request $request)
 {
     $user_form = $request->get('user');
     $user = new User();
     $user->fill($user_form);
     $user->password = Hash::make($user_form['password']);
     $user->faculty_id = $user_form["faculty_id"];
     $user->save();
     $user->roles()->sync($user_form["role_ids"]);
     return redirect('/backend/user');
 }
开发者ID:pchaow,项目名称:SuccessModel5,代码行数:11,代码来源:UserController.php

示例8: createByVkData

 public function createByVkData($vkData)
 {
     $user = new User();
     $user->provider_id = $vkData['uid'];
     $user->name = $vkData['first_name'] . ' ' . $vkData['last_name'];
     $user->screen_name = $vkData['screen_name'];
     $user->save();
     $user->roles()->attach(Role::getDefaultRole());
     copy($vkData['photo_big'], public_path() . '/img/avatars/users/' . $user->id . '.jpg');
     return $user;
 }
开发者ID:AlexYaroma,项目名称:mightyducks,代码行数:11,代码来源:UserRepository.php

示例9: postAdd

 /**
  * Adds an user
  *
  * @param AddUserRequest $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postAdd(AddUserRequest $request)
 {
     $user = new User();
     $user->changeProfile($request);
     $user->roles()->attach($request->input('roles'));
     $user->changeSettings($request);
     if ($request->file('avatar')) {
         $user->changeAvatar($request);
     }
     $user->save();
     User::flushCache($user);
     flash()->success(trans('users.add_success'));
     return redirect()->back();
 }
开发者ID:noikiy,项目名称:Laravel5Starter,代码行数:20,代码来源:AdminUsersController.php

示例10: handle

 /**
  * Execute the job.
  *
  * @throws CannotRemoveRolesException
  *
  * @return bool
  */
 public function handle()
 {
     $this->user->name = $this->request->input('name', $this->user->name);
     $this->user->email = $this->request->input('email');
     $password = $this->request->input('password');
     // Verify before changing the users password that it's not empty.
     if (!empty($password)) {
         // If the user doesn't have a set password mutator,
         // we'll encrypt the password.
         if (!$this->user->hasSetMutator('password')) {
             $password = bcrypt($password);
         }
         $this->user->password = $password;
     }
     // Retrieve the administrators name.
     $adminName = Role::getAdministratorName();
     $roles = $this->request->input('roles', []);
     // Retrieve all administrator users.
     $administrators = $this->user->whereHas('roles', function (Builder $builder) use($adminName) {
         $builder->whereName($adminName);
     })->get();
     // Retrieve the administrator role.
     $admin = Role::whereName($adminName)->first();
     // We need to verify that if the user is trying to remove all roles on themselves,
     // and they are the only administrator, that we throw an exception notifying them
     // that they can't do that. Though we want to allow the user to remove the
     // administrator role if more than one administrator exists.
     if (count($roles) === 0 && $this->user->hasRole($admin) && $this->user->getKey() === auth()->user()->getKey() && count($administrators) === 1) {
         throw new CannotRemoveRolesException("Unable to remove the administrator role. You're the only administrator.");
     }
     if ($this->user->save()) {
         $this->user->roles()->sync($roles);
         return true;
     }
     return false;
 }
开发者ID:stevebauman,项目名称:administration,代码行数:43,代码来源:Update.php

示例11: storeUser

 public function storeUser($request)
 {
     $user = new User();
     //find a new api_token
     $token = "";
     do {
         $token = str_random(60);
     } while (User::where("api_token", "=", $token)->first() instanceof User);
     $user->api_token = $token;
     $user->name = $request->name;
     $user->email = $request->email;
     $user->password = bcrypt($request->password);
     $result = $user->save();
     $roles = array_flatten($request->roles);
     $user->roles()->attach($roles);
     return $result;
 }
开发者ID:jaumesala,项目名称:opendata-maps,代码行数:17,代码来源:UserRepository.php

示例12: createUserFromSoap

 private function createUserFromSoap($username, $password)
 {
     $infoResult = $this->getUserInfoFromSoap($username, $password);
     $user = new User();
     $user->username = $username;
     $user->title = $infoResult->Title;
     $user->firstname = $infoResult->FirstName_TH;
     $user->lastname = $infoResult->LastName_TH;
     $user->email = $username . "@up.ac.th";
     //        $user->save();
     $faculty = Faculty::where('name_th', '=', $infoResult->Faculty)->first();
     if ($faculty) {
         $user->faculty_id = $faculty->id;
     }
     $user->save();
     $role = Role::where('key', '=', 'researcher')->first();
     $user->roles()->attach($role->id);
     $user->faculty;
     return $user;
 }
开发者ID:pchaow,项目名称:SuccessModel5,代码行数:20,代码来源:BackendController.php

示例13: save

 public function save()
 {
     $chk = User::where("email", "=", Input::get('email'))->first();
     if (empty($chk)) {
         $user = new User();
         $user->first_name = Input::get('first_name');
         $user->last_name = Input::get('last_name');
         $user->email = Input::get('email');
         $user->password = Hash::make(Input::get('password'));
         $user->user_type = 1;
         $user->save();
         if (!empty(Input::get('roles'))) {
             $user->roles()->sync([Input::get('roles')]);
         }
         return redirect()->route('admin.systemusers.view');
     } else {
         Session::flash("usenameError", "Username already exist");
         return redirect()->back();
     }
 }
开发者ID:sushilcs111,项目名称:td,代码行数:20,代码来源:SystemUsersController.php

示例14: run

 public function run()
 {
     $faker = Faker\Factory::create();
     $user = new User();
     $user->username = 'admin';
     $user->password = Hash::make('admin');
     $user->email = 'admin@domain.com';
     $user->deleted_at = null;
     $user->confirmed_at = \Carbon\Carbon::now();
     $user->save();
     $user->roles()->save(Role::find(1));
     for ($i = 0; $i < 50; $i++) {
         $user = new User();
         $user->username = $faker->userName;
         $user->password = Hash::make('password');
         $user->email = $faker->safeEmail;
         $user->deleted_at = null;
         $user->confirmed_at = \Carbon\Carbon::now();
         $user->save();
         $user->roles()->save(Role::find(2));
     }
 }
开发者ID:Denniskevin,项目名称:Laravel5Starter,代码行数:22,代码来源:UsersSeeder.php

示例15: postAdd

 /**
  * Adds an user
  *
  * @param AddUserRequest $request
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postAdd(AddUserRequest $request)
 {
     $user = new User();
     $user->changeProfile($request);
     $user->roles()->attach($request->input('roles'));
     $user->changeSettings($request);
     if ($request->file('avatar') && Settings::get('use_avatars')) {
         $response = Icr::uploadImage($request->file('avatar'), 'avatar');
         if ($response instanceof \Exception) {
             flash()->error($response->getMessage());
             return redirect()->back();
         }
         $user->changeAvatar($response);
     }
     $user->save();
     User::flushCache($user);
     flash()->success(trans('users.add_success'));
     return redirect()->back();
 }
开发者ID:Denniskevin,项目名称:Laravel5Starter,代码行数:26,代码来源:AdminUsersController.php


注:本文中的app\models\User::roles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。