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


PHP Role::attachPermissions方法代码示例

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


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

示例1: create

 /**
  * @param  $input
  * @throws GeneralException
  * @return bool
  */
 public function create($input)
 {
     if (Role::where('role_name', $input['role_name'])->first()) {
         throw new GeneralException('That role already exists. Please choose a different name.');
     }
     if (count($input['assignees_permissions']) == 0) {
         throw new GeneralException('You must select at least one permission for this role.');
     }
     $role = new Role();
     $role->role_name = $input['role_name'];
     $role->role_slug = $input['role_slug'];
     $role->role_description = $input['role_description'];
     if ($role->save()) {
         $current = $input['assignees_permissions'];
         $permissions = [];
         if (count($current)) {
             foreach ($current as $perm) {
                 if (is_numeric($perm)) {
                     array_push($permissions, $perm);
                 }
             }
         }
         $role->attachPermissions($permissions);
         return true;
     }
     throw new GeneralException('There was a problem creating this role. Please try again.');
 }
开发者ID:aysenli,项目名称:laravel5-backend,代码行数:32,代码来源:RoleRepository.php

示例2: setupRolesPermissions

 public function setupRolesPermissions()
 {
     $master = User::findOrFail(1);
     if ($master) {
         // Create role
         $owner = new Role();
         $owner->name = 'master';
         $owner->display_name = 'Project Owner';
         $owner->description = 'The Master of Universe';
         $owner->save();
         // Create permissions
         $createUser = new Permission();
         $createUser->name = 'user-create';
         $createUser->display_name = 'Create Users';
         $createUser->description = 'Create new users';
         $createUser->save();
         $editUser = new Permission();
         $editUser->name = 'user-edit';
         $editUser->display_name = 'Edit Users';
         $editUser->description = 'Edit existing users';
         $editUser->save();
         $deleteUser = new Permission();
         $deleteUser->name = 'user-delete';
         $deleteUser->display_name = 'Delete Users';
         $deleteUser->description = 'Delete existing users';
         $deleteUser->save();
         // Attach permissions
         $owner->attachPermissions([$createUser, $editUser, $deleteUser]);
         // Attach roles
         $master->attachRole($owner);
         // using facade
     }
     return redirect()->route('access.test');
 }
开发者ID:ricardoaugusto,项目名称:laravel-foundation,代码行数:34,代码来源:AccessController.php

示例3: EventManager

 public static function EventManager($eventId, $permissions)
 {
     return DB::transaction(function () use($eventId, $permissions) {
         $rolename = RoleNames::EventManager($eventId);
         $role = new Role();
         $role->name = $rolename;
         $role->save();
         $role->attachPermissions($permissions);
         return $role;
     });
 }
开发者ID:a161527,项目名称:cs319-p2t5,代码行数:11,代码来源:RoleCreate.php


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