當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。