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


PHP Role::attachPermission方法代碼示例

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


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

示例1: createPermissionRoles

 public static function createPermissionRoles($permissions)
 {
     foreach ($permissions as $p) {
         $role = new Role();
         $role->name = $p->name;
         $role->save();
         $role->attachPermission($p);
     }
 }
開發者ID:a161527,項目名稱:cs319-p2t5,代碼行數:9,代碼來源:RoleCreate.php

示例2: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('roles')->delete();
     /**
      * Role Attributes
      *
      * name:    Unique name for the permission, used for looking up permission information in the
      *             application layer. For example: "create-post", "edit-user", "post-payment", "mailing-list-subscribe".
      *
      * display_name:    Human readable name for the permission. Not necessarily unique, and is optional.
      *                     For example "Create Posts", "Edit Users", "Post Payments", "Subscribe to mailing list".
      *
      * description:     A more detailed explanation of the Role. This is also optional.
      *
      * permissions: A list of permission names to assign to the user.  Optional.
      */
     $roles = array(array('name' => 'owner', 'display_name' => 'Owner', 'description' => 'Owner of the management system. Has access to all aspects of the system.', 'permissions' => PermissionNames::AllGlobalPermissions()));
     foreach ($roles as $r) {
         $entry = new Role();
         $entry->name = $r['name'];
         if (array_key_exists('permissions', $r)) {
             $permissions = $r['permissions'];
             unset($r['permissions']);
         }
         if (array_key_exists('display_name', $r)) {
             $entry->display_name = $r['display_name'];
         }
         if (array_key_exists('description', $r)) {
             $entry->description = $r['description'];
         }
         $entry->save();
         if (isset($permissions)) {
             foreach ($permissions as $p) {
                 $entry->attachPermission(Permission::where('name', $p)->get()->first());
             }
             unset($permissions);
         }
     }
     $rolePermissions = Permission::whereIn('name', PermissionNames::AllGlobalPermissions())->get();
     RoleCreate::createPermissionRoles($rolePermissions);
 }
開發者ID:a161527,項目名稱:cs319-p2t5,代碼行數:46,代碼來源:DefaultRolesSeeder.php

示例3: run

 public function run()
 {
     DB::table('Roles')->delete();
     $role = new Role();
     $role->name = 'admin';
     $role->display_name = 'Administrateur du système';
     $role->description = 'Cet usager a tous les droits sur le système, c\'est le super admin';
     $role->save();
     $permission = Permission::where('name', '=', 'ajout-prof')->first();
     $role->attachPermission($permission);
     $permission = Permission::where('name', '=', 'ajout-etudiant')->first();
     $role->attachPermission($permission);
     $permission = Permission::where('name', '=', 'ajout-classe')->first();
     $role->attachPermission($permission);
     $permission = Permission::where('name', '=', 'passer-test')->first();
     $role->attachPermission($permission);
     $permission = Permission::where('name', '=', 'enseigner')->first();
     $role->attachPermission($permission);
     $role = new Role();
     $role->name = 'professeur';
     $role->display_name = 'Professeur';
     $role->description = 'Les professeurs en charge des étudiants';
     $role->save();
     $permission = Permission::where('name', '=', 'ajout-etudiant')->first();
     $role->attachPermission($permission);
     $permission = Permission::where('name', '=', 'passer-test')->first();
     $role->attachPermission($permission);
     $permission = Permission::where('name', '=', 'enseigner')->first();
     $role->attachPermission($permission);
     $role = new Role();
     $role->name = 'etudiant';
     $role->display_name = 'Étudiants';
     $role->description = 'Les étudiants qui sont gérés par les professeurs';
     $role->save();
     $permission = Permission::where('name', '=', 'passer-test')->first();
     $role->attachPermission($permission);
 }
開發者ID:BenoitDesrosiers,項目名稱:GestionNoteEtudiant51,代碼行數:37,代碼來源:DatabaseSeeder.php


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