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