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


PHP Role::whereName方法代码示例

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


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

示例1: addRole

 /**
  * Add a Role to a User
  *
  * @param multiple $role Role to add, might by instance of Role or name of role as string
  */
 public function addRole($role)
 {
     if (is_string($role)) {
         $role = Role::whereName($role)->firstOrFail();
     }
     return $this->roles()->save($role);
 }
开发者ID:guenthertheilen,项目名称:laravel-boilerplate,代码行数:12,代码来源:User.php

示例2: assign

 /**
  * Assign role(s) to a user.
  *
  * @param  string|object $role
  * @return boolean
  */
 public function assign($role)
 {
     if (is_string($role)) {
         return $this->roles()->save(Role::whereName($role)->firstOrFail());
     }
     return $this->roles()->save($role);
 }
开发者ID:NathanCH,项目名称:urban-laravel,代码行数:13,代码来源:User.php

示例3: create

 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     $user = User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
     $organisation = Organisation::create(['name' => $data['organisationName']]);
     $role = Role::whereName('owner')->first();
     $userOrganisationRole = new UserOrganisationRole(['user_id' => $user->id, 'organisation_id' => $organisation->id, 'role_id' => $role->id]);
     $user->organisationRoles()->save($userOrganisationRole);
     return $user;
 }
开发者ID:vhinmanansala,项目名称:Eloquent,代码行数:15,代码来源:AuthController.php

示例4: store

 /**
  * save a user
  * @param $data
  */
 public function store($data)
 {
     $data = $this->prepareData($data);
     $user = $this->model->create($data);
     $role = isset($data['role']) ? $data['role'] : Role::whereName('member')->first();
     $user->createProfile();
     $user->assignRole($role);
     return $user;
 }
开发者ID:alons182,项目名称:guanacastevende,代码行数:13,代码来源:UserRepository.php

示例5: assignRole

 public function assignRole($role)
 {
     // if given is string
     if (is_string($role)) {
         return $this->roles()->save(Role::whereName($role)->firstOrfail());
     }
     // given is collection
     return $this->roles()->save($role);
 }
开发者ID:WPTEbilkent,项目名称:WPTE,代码行数:9,代码来源:User.php

示例6: run

 public function run()
 {
     DB::table('role_user')->delete();
     $user = User::whereName('corean')->FirstOrFail();
     $role_id = Role::whereName('manager')->pluck('id');
     $user->saveRoles([$role_id[0]]);
     $user = User::whereName('test')->FirstOrFail();
     $role_id = Role::whereName('member')->pluck('id');
     $user->saveRoles([$role_id[0]]);
 }
开发者ID:corean,项目名称:LearningLaravel,代码行数:10,代码来源:DatabaseSeeder.php

示例7: ownAdminRole

 /**
  * An admin can not remove its own admin privileges
  *
  * @return bool
  */
 public function ownAdminRole($attribute, $value, $parameters, $validator)
 {
     $userId = $parameters[0];
     $ownId = $parameters[1];
     $adminRoleId = Role::whereName('admin')->pluck('id')->first();
     if (in_array($adminRoleId, $value)) {
         return true;
     }
     return $userId != $ownId;
 }
开发者ID:guenthertheilen,项目名称:laravel-boilerplate,代码行数:15,代码来源:RoleValidators.php

示例8: run

 public function run()
 {
     DB::table('users')->delete();
     $adminRole = Role::whereName('administrator')->first();
     $userRole = Role::whereName('user')->first();
     $user = User::create(array('first_name' => 'John', 'last_name' => 'Doe', 'email' => 'j.doe@codingo.me', 'password' => Hash::make('password')));
     $user->assignRole($adminRole);
     $user = User::create(array('first_name' => 'Jane', 'last_name' => 'Doe', 'email' => 'jane.doe@codingo.me', 'password' => Hash::make('janesPassword')));
     $user->assignRole($userRole);
 }
开发者ID:nouzun,项目名称:gamification,代码行数:10,代码来源:UserSeeder.php

示例9: register

 public function register($data)
 {
     $user = new User();
     $user->email = $data['email'];
     $user->first_name = ucfirst($data['first_name']);
     $user->last_name = ucfirst($data['last_name']);
     $user->password = Hash::make($data['password']);
     $user->save();
     //Assign Role
     $role = Role::whereName('user')->first();
     $user->assignRole($role);
 }
开发者ID:nouzun,项目名称:gamification,代码行数:12,代码来源:UserRepository.php

示例10: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $user = Auth::user();
     //dd($user->email);
     if ($user) {
         $role = Role::whereName('guest')->first();
         if ($user->hasRole($role)) {
             return $next($request);
         }
     }
     return redirect('/');
 }
开发者ID:imladrisol,项目名称:onlineExam,代码行数:19,代码来源:UserPanel.php

示例11: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $role = Role::whereName('admin')->firstOrFail();
     $role->addPermission('permissions-index');
     $role->addPermission('permissions-create');
     $role->addPermission('permissions-edit');
     $role->addPermission('roles-index');
     $role->addPermission('roles-create');
     $role->addPermission('roles-edit');
     $role->addPermission('users-index');
     $role->addPermission('users-create');
     $role->addPermission('users-edit');
 }
开发者ID:guenthertheilen,项目名称:laravel-boilerplate,代码行数:18,代码来源:PermissionRoleTableSeeder.php

示例12: store

 public function store($data)
 {
     $data = $this->prepareData($data);
     $data['image'] = isset($data['image']) ? $this->storeImage($data['image'], $data['name'] . '-' . getUniqueNumber(), 'sellers', null, null, 640, null, false) : '';
     $seller = $this->model->create($data);
     $profile = new Profile($data);
     $seller->createProfile($profile);
     $role = isset($data['role']) ? $data['role'] : Role::whereName('seller')->firstOrFail();
     $seller->assignRole($role);
     if (isset($data['clients'])) {
         $seller->assignClient($data['clients']);
     }
     return $seller;
 }
开发者ID:alons182,项目名称:crm,代码行数:14,代码来源:SellerRepo.php

示例13: create_user

 /**
  * Function create user
  * @author  Tran Van Moi <[moitran92@gmail.com]>
  * @since  2015/05/13
  * @param  array $user_info
  * @param  string $role_name
  * @return object
  */
 public static function create_user($user_info, $role_name)
 {
     $user = new User();
     $user->name = $user_info['name'];
     $user->uid = empty($user_info['id']) ? 'res_local' : $user_info['id'];
     $user->email = $user_info['email'];
     $user->image = $user_info['image'];
     $user->password = Hash::make($user_info['password']);
     if (isset($user_info['birthday'])) {
         $user->birthday = $user_info['birthday'];
     }
     if (isset($user_info['address'])) {
         $user->address = $user_info['address'];
     }
     $user->save();
     // attack role to user
     $role = Role::whereName($role_name)->first();
     $user->attachRole($role);
     return $user;
 }
开发者ID:ambarsetyawan,项目名称:laravel-1,代码行数:28,代码来源:User.php

示例14: updateRoles

 public function updateRoles(User $user, Request $request, $user_id)
 {
     $userModel = User::find($user_id);
     $userModel->name = $request->get('name');
     $userModel->email = $request->get('email');
     $userModel->save();
     // detach role from user
     $userModel->detachRoles(Role::all());
     //insert new roles
     foreach ($request->get('role') as $role_request) {
         $userModel->attachRole(Role::whereName($role_request)->first());
     }
     return Redirect::back()->with('msg', ' was successfully updated.');
 }
开发者ID:encry2024,项目名称:soa_5,代码行数:14,代码来源:UserController.php

示例15: apiRoleDetails

 /**
  * API for retrieving details of a single role
  */
 public function apiRoleDetails(Role $role)
 {
     return $roleWithPermissions = Role::whereName($role->name)->with('permissions')->first();
 }
开发者ID:goatatwork,项目名称:goatshark,代码行数:7,代码来源:UsersController.php


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