當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::hasRole方法代碼示例

本文整理匯總了PHP中app\User::hasRole方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::hasRole方法的具體用法?PHP User::hasRole怎麽用?PHP User::hasRole使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\User的用法示例。


在下文中一共展示了User::hasRole方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: checkRoleInheritance

 protected function checkRoleInheritance(User $user = null, $roleName)
 {
     //未登入直接不通過
     if (!$user) {
         return false;
     }
     //直接擁有該角色
     if ($user->hasRole($roleName)) {
         return true;
     }
     //檢查角色是否存在
     $role = Role::where('name', $roleName)->first();
     if (!$role) {
         return false;
     }
     //檢查擁有的角色,是否繼承欲檢查之角色
     $roleList = $user->roles;
     foreach ($roleList as $roleItem) {
         if (isset(static::$inheritance[$roleItem->name]) || array_key_exists($roleItem->name, static::$inheritance)) {
             //繼承表有該角色
             $roleInheritanceList = static::$inheritance[$roleItem->name];
             if (is_array($roleInheritanceList)) {
                 foreach ($roleInheritanceList as $roleInheritance) {
                     if ($roleInheritance = $role->name) {
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
開發者ID:alhs1995,項目名稱:DBFP,代碼行數:32,代碼來源:RoleLimit.php

示例2: store

 public function store(Request $request, $id = null)
 {
     if (isset($id)) {
         if ($request->input('password')) {
             $validator = Validator::make($request->only('username', 'email', 'password', 'password_confirmation'), $this->user->update_rules_with_password);
         } else {
             $validator = Validator::make($request->only('username', 'email', 'password', 'password_confirmation'), $this->user->update_rules);
         }
     } else {
         $validator = Validator::make($request->only('username', 'email', 'password', 'password_confirmation'), $this->user->create_rules);
     }
     if ($validator->passes()) {
         if (isset($id)) {
             $user = $this->user->find($id);
         } else {
             $user = new User();
         }
         $user->username = $request->input('username');
         $user->email = $request->input('email');
         if ($request->input('password')) {
             $user->password = Hash::make($request->input('password'));
         }
         $user->save();
         $role = Role::where('role_name', 'admin')->first();
         if ($request->input('admin')) {
             $user->roles()->attach($role);
         } else {
             if ($user->hasRole('admin')) {
                 $user->roles()->detach($role);
             }
         }
         return redirect()->to('users')->with(['success' => 'Saved ' . $user->username]);
     } else {
         return redirect()->back()->withInput()->withErrors($validator->messages());
     }
 }
開發者ID:mikeminckler,項目名稱:unilog,代碼行數:36,代碼來源:UsersController.php

示例3: show

 public function show(User $user, Group $group)
 {
     return $user->hasRole('manager') && $user->organization->id === $group->organization->id;
 }
開發者ID:ppawlas,項目名稱:swop,代碼行數:4,代碼來源:GroupPolicy.php

示例4: pdf

 public function pdf(User $user, Report $report)
 {
     return $user->hasRole('manager') && $user->id === $report->owner->id;
 }
開發者ID:ppawlas,項目名稱:swop,代碼行數:4,代碼來源:ReportPolicy.php

示例5: before

 /**
  * Determine if user is admin then bypass all checks
  *
  * @param  \App\User  $user
  * @param  \App\Model\Permission  $permission
  * @return bool
  */
 public function before($user, $ability)
 {
     if ($user->hasRole('admin')) {
         return true;
     }
 }
開發者ID:jaffarhussain1011,項目名稱:laravel-authorization-demo,代碼行數:13,代碼來源:PermissionPolicy.php

示例6: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(User $user, $role_id)
 {
     if (!Auth::user()->can('administrate-permissions')) {
         abort(401, "You can not edit user permissions");
     }
     $role = Role::where('id', '=', $role_id)->firstOrFail();
     if (!$user->hasRole($role->name)) {
         abort(403, "User doesn't have the role id of ({$role_id})");
     }
     $user->removeUserRole($role_id);
     return $user;
 }
開發者ID:dwoodard,項目名稱:IserveU,代碼行數:18,代碼來源:UserRoleController.php

示例7: authenticated

 public function authenticated($request, User $user)
 {
     if ($user->hasRole('customer')) {
         $this->redirectTo = '/customer/';
     }
     return redirect()->intended($this->redirectPath());
 }
開發者ID:vidmahovic,項目名稱:ep-store,代碼行數:7,代碼來源:AuthController.php


注:本文中的app\User::hasRole方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。