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


PHP Role::perms方法代码示例

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


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

示例1: run

 public function run()
 {
     $adminEmail = Config::get('madison.seeder.admin_email');
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     $independent_sponsor = new Role();
     $independent_sponsor->name = 'Independent Sponsor';
     $independent_sponsor->save();
     $permIds = array();
     foreach ($this->adminPermissions as $permClass => $data) {
         $perm = new Permission();
         foreach ($data as $key => $val) {
             $perm->{$key} = $val;
         }
         $perm->save();
         $permIds[] = $perm->id;
     }
     $admin->perms()->sync($permIds);
     $user = User::where('email', '=', $adminEmail)->first();
     $user->attachRole($admin);
     $createDocPerm = new Permission();
     $createDocPerm->name = "independent_sponsor_create_doc";
     $createDocPerm->display_name = "Independent Sponsoring";
     $createDocPerm->save();
     $independent_sponsor->perms()->sync(array($createDocPerm->id));
 }
开发者ID:DCgov,项目名称:dc-madison,代码行数:27,代码来源:RbacSeeder.php

示例2: store

 /**
  * Store role
  *
  * @param array $roleData            
  * @throws NotFoundException, ValidationException
  * @return \App\Models\RoleModel
  */
 public function store($roleData)
 {
     try {
         if (array_get($roleData, 'id')) {
             $role = RoleModel::findOrFail((int) array_get($roleData, 'id'))->fill($roleData);
         } else {
             $role = new RoleModel();
             $role->fill($roleData);
         }
     } catch (Exception $e) {
         throw new NotFoundException(trans('app.notFound'));
     }
     if (!$role->validate()) {
         throw new ValidationException(trans('app.correctErrors'), $role->errors()->toArray());
     }
     try {
         $role->save();
         // associate permissions
         if (array_get($roleData, 'permission_id')) {
             $role->perms()->sync(array_get($roleData, 'permission_id'));
         }
     } catch (Exception $e) {
         throw $e;
     }
     return $role;
 }
开发者ID:jasekz,项目名称:filament-for-laravel-5,代码行数:33,代码来源:Role.php

示例3: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = ['name' => 'required|alpha_dash|min:1|max:255', 'display_name' => 'string|max:255', 'description' => 'string', 'permissions' => 'array|integerInArray|existsInArray:permission,id'];
     $validator = Validator::make(Input::only(array_keys($rules)), $rules);
     if ($validator->fails()) {
         throw new ResourceException($validator->errors()->first());
     }
     $role = new Role();
     $fields = ['name'];
     foreach ($fields as $key => $field) {
         if (Input::has($field)) {
             $role->{$field} = Input::get($field);
         }
     }
     //field which can null/empty string
     $fields = ['description', 'display_name'];
     foreach ($fields as $key => $field) {
         if (Input::get($field) === '') {
             $role->{$field} = null;
         } elseif (Input::has($field)) {
             $role->{$field} = Input::get($field);
         }
     }
     $role->save();
     $role->perms()->sync(Input::get('permissions', []));
     return $this->show($role->id);
 }
开发者ID:TolotraRam,项目名称:laravel-angular-cms,代码行数:32,代码来源:RoleController.php

示例4: createRbacRules

 public function createRbacRules()
 {
     $this->destroyRbacRules();
     $ownerRole = new Role();
     $ownerRole->name = "group_{$this->id}_owner";
     $ownerRole->save();
     $permissions = $this->getPermissionsArray();
     $permIds = array();
     $permLookup = array();
     foreach ($permissions as $perm) {
         $permModel = new Permission();
         foreach ($perm as $key => $val) {
             $permModel->{$key} = $val;
         }
         $permModel->save();
         $permIds[] = $permModel->id;
         switch ($perm['name']) {
             case "group_{$this->id}_create_document":
                 $permLookup['create'] = $permModel->id;
                 break;
             case "group_{$this->id}_edit_document":
                 $permLookup['edit'] = $permModel->id;
                 break;
             case "group_{$this->id}_delete_document":
                 $permLookup['delete'] = $permModel->id;
                 break;
             case "group_{$this->id}_manage_document":
                 $permLookup['manage'] = $permModel->id;
                 break;
         }
     }
     $ownerRole->perms()->sync($permIds);
     $editorRole = new Role();
     $editorRole->name = "group_{$this->id}_editor";
     $editorRole->save();
     $editorRole->perms()->sync(array($permLookup['create'], $permLookup['edit'], $permLookup['manage']));
     $staffRole = new Role();
     $staffRole->name = "group_{$this->id}_staff";
     $staffRole->save();
     $users = array(static::ROLE_OWNER => $this->findUsersByRole(static::ROLE_OWNER), static::ROLE_EDITOR => $this->findUsersByRole(static::ROLE_EDITOR), static::ROLE_STAFF => $this->findUsersByRole(static::ROLE_STAFF));
     foreach ($users as $role => $userList) {
         foreach ($userList as $userObj) {
             switch ($role) {
                 case static::ROLE_OWNER:
                     $userObj->attachRole($ownerRole);
                     break;
                 case static::ROLE_EDITOR:
                     $userObj->attachRole($editorRole);
                     break;
                 case static::ROLE_STAFF:
                     $userObj->attachRole($staffRole);
                     break;
             }
         }
     }
 }
开发者ID:johnfelipe,项目名称:madison,代码行数:56,代码来源:Group.php

示例5: setupFoundorAndBaseRolsPermission

 public function setupFoundorAndBaseRolsPermission()
 {
     // Create Roles
     $founder = new Role();
     $founder->name = 'Founder';
     $founder->save();
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     // Create User
     $user = new User();
     $user->username = 'admin';
     $user->display_name = 'Admin';
     $user->email = 'admin@local.com';
     $user->password = 'admin';
     if (!$user->save()) {
         Log::info('Unable to create user ' . $user->username, (array) $user->errors());
     } else {
         Log::info('Created user "' . $user->username . '" <' . $user->email . '>');
     }
     // Attach Roles to user
     $user->roles()->attach($founder->id);
     // Create Permissions
     $manageContent = new Permission();
     $manageContent->name = 'manage_contents';
     $manageContent->display_name = 'Manage Content';
     $manageContent->save();
     $manageUsers = new Permission();
     $manageUsers->name = 'manage_users';
     $manageUsers->display_name = 'Manage Users';
     $manageUsers->save();
     // Assign Permission to Role
     $founder->perms()->sync([$manageContent->id, $manageUsers->id]);
     $admin->perms()->sync([$manageContent->id]);
 }
开发者ID:axex,项目名称:kratos,代码行数:35,代码来源:2016_01_25_135943_entrust_setup_tables.php


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