当前位置: 首页>>代码示例>>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;未经允许,请勿转载。