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


PHP Role::attachPermission方法代码示例

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


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

示例1: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $superAdmin = new Role();
     $superAdmin->name = 'super admin';
     $superAdmin->display_name = 'Super admin';
     $superAdmin->description = 'This role holder has right to everything on the application.';
     $superAdmin->save();
     $authUser = new Role();
     $authUser->name = 'auth user';
     $authUser->display_name = 'Authenticated User';
     $authUser->description = 'This is the basic role which every registered user will get by default.';
     $authUser->save();
     /**
      * Manage Role Permissions
      */
     $manageRolePermission = new Permission();
     $manageRolePermission->name = 'manage-role-perm';
     $manageRolePermission->display_name = 'Manage Role & Permissions';
     $manageRolePermission->description = 'Manage roles and give permissions to role holders.';
     $manageRolePermission->save();
     $superAdmin->attachPermission($manageRolePermission);
     /**
      * Manage User Permission
      */
     $manageUserPermission = new Permission();
     $manageUserPermission->name = 'manage-users';
     $manageUserPermission->display_name = 'Manage Users';
     $manageUserPermission->description = 'Manage Users';
     $manageUserPermission->save();
     $superAdmin->attachPermission($manageUserPermission);
     /**
      * Manage Permission to see Activity
      */
     $manageActivityViewPermission = new Permission();
     $manageActivityViewPermission->name = 'view-activity';
     $manageActivityViewPermission->display_name = 'View Activity';
     $manageActivityViewPermission->description = 'View the different user activity in the system.';
     $manageActivityViewPermission->save();
     $superAdmin->attachPermission($manageActivityViewPermission);
     /**
      * Manage settings for application
      */
     $manageSettingsPermission = new Permission();
     $manageSettingsPermission->name = 'manage-settings';
     $manageSettingsPermission->display_name = 'Manage Settings';
     $manageSettingsPermission->description = 'Manage Settings for the application. User can change settings.';
     $manageSettingsPermission->save();
     $superAdmin->attachPermission($manageSettingsPermission);
     $user = User::create(['name' => 'Amitav Roy', 'email' => 'reachme@amitavroy.com', 'password' => \Illuminate\Support\Facades\Hash::make('password'), 'first_name' => 'Amitav', 'last_name' => 'Roy', 'status' => 1]);
     $authUser = User::create(['name' => 'Jhon Doe', 'email' => 'jhon.doe@gmail.com', 'password' => \Illuminate\Support\Facades\Hash::make('password'), 'first_name' => 'Jhon', 'last_name' => 'Doe', 'status' => 1]);
     $authUser->attachRole($authUser);
     $user->attachRole($superAdmin);
 }
开发者ID:amitavroy,项目名称:mywall,代码行数:58,代码来源:UserTableSeeder.php

示例2: createdummies

 /**
  * Create a new controller instance.
  *
  * @return void
  */
 public function createdummies()
 {
     $wizard = new Role();
     $wizard->name = 'Wizard';
     $wizard->save();
     $muggle = new Role();
     $muggle->name = 'Muggle';
     $muggle->save();
     $castspells = new Permission();
     $castspells->name = 'can_castspells';
     $castspells->display_name = 'Can Cast Spells';
     $castspells->description = 'Enables you to cast awesome spells';
     $castspells->save();
     $bestupid = new Permission();
     $bestupid->name = 'can_bestupid';
     $bestupid->display_name = 'Be stupid';
     $bestupid->description = 'Enables you to be stupid and not see the magic around you';
     $bestupid->save();
     $wizard->attachPermission($castspells);
     $muggle->attachPermission($bestupid);
     $wiz_role = DB::Table('roles')->where('name', '=', 'Wizard')->pluck('id');
     $mug_role = DB::Table('roles')->where('name', '=', 'Muggle')->pluck('id');
     $harryPotter = User::where('username', '=', 'HarryPotter')->first();
     $harryPotter->roles()->attach($wiz_role);
     $smithwee = User::where('username', '=', 'SmithWee')->first();
     $smithwee->roles()->attach($mug_role);
     return 'Abracadabra!';
 }
开发者ID:muschottkey,项目名称:bausbaus,代码行数:33,代码来源:ACLController.php

示例3: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $admin = new Role();
     $admin->name = "administrator";
     $admin->display_name = "Administrator";
     $admin->description = "An administrator gains access to everything.";
     $admin->power = 1000;
     $admin->save();
     $dashboardAccess = new Permission();
     $dashboardAccess->name = "dashboard.access";
     $dashboardAccess->display_name = "Dashboard access";
     $dashboardAccess->description = "Grant's a user access to the dashboard.";
     $dashboardAccess->save();
     $admin->attachPermission($dashboardAccess);
 }
开发者ID:Teamelite,项目名称:Dashboard,代码行数:20,代码来源:AccessControlSeeder.php

示例4: run

 public function run()
 {
     $admin = new \App\Role();
     $admin->name = 'admin';
     $admin->display_name = 'Administrador de usuarios';
     // opcional
     $admin->description = 'Se permite al usuario gestionar y editar otros usuarios';
     // opcional
     $admin->save();
     /**
      * Creamos un Usuario
      */
     $user = new \App\User();
     $user->nom_usuario = 'Juan Sebastian';
     $user->ape_usuario = 'Maya Narvaez';
     $user->num_identificacion = '1085293173';
     $user->tel_usuario = '7363301';
     $user->cel_usuario = '3147708366';
     $user->user_login = 'jumaya23';
     $user->email = 'jumaya19@gmail.com';
     $user->password = bcrypt('12345');
     $user->estado_user = 'REG';
     $user->id_municipio = '1';
     $user->id_tipo_secretaria = '1';
     $user->id_tipo_identificacion = '1';
     $user->id_cargo_usuario = '1';
     $user->save();
     /**
      * Asignamos el Rol admin al usuario
      * Usando el alias del paquete
      */
     // $user->attachRole($admin);// podemos enviar el Rol o el id del Rol
     /**
      * O usamos Eloquent
      */
     $user->roles()->attach($admin->id);
     //usamos solamente el id del Rol
     /**
      * Creamos permisos
      */
     $createPost = new \App\Permission();
     $createPost->name = 'gestion_gene';
     $createPost->display_name = 'Gestion General';
     // opcional
     // Allow a user to...
     $createPost->description = 'Menú de Gestion General';
     // opcional
     $createPost->save();
     $editUser = new \App\Permission();
     $editUser->name = 'gestion_not';
     $editUser->display_name = 'Gestion de Notificaciones';
     // opcional
     // Allow a user to...
     $editUser->description = 'Menú de Notificaciones';
     // opcional
     $editUser->save();
     /**
      * Al Rol admin le asignamos los permisos
      */
     $admin->attachPermission($createPost);
     //esto es equivalente a $admin->perms()->sync(array($createPost->id));
     // $admin->attachPermissions([$createPost, $editUser]); //esto es equivalente a $admin->perms()->sync(array($createPost->id, $editUser->id));
 }
开发者ID:jumaya,项目名称:redbpim,代码行数:63,代码来源:AsignarRolesTableSeeder.php

示例5: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     /**
      * Creating Roles
      */
     $admin = new Role();
     $admin->name = 'admin';
     $admin->display_name = 'Administrator';
     $admin->description = 'Administration of the System';
     $admin->save();
     $registered = new Role();
     $registered->name = 'registered';
     $registered->display_name = 'Registered User';
     $registered->description = 'Registered User of the System';
     $registered->save();
     $moderator = new Role();
     $moderator->name = 'moderator';
     $moderator->display_name = 'Moderator';
     $moderator->description = 'Moderator of the System';
     $moderator->save();
     /**
      * Creating Permissions
      */
     /**
      * Subject
      */
     $permission = new Permission();
     $permission->name = 'create-subject';
     $permission->display_name = 'Create Subject';
     // optional
     $permission->description = 'Create new Subject in The system';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $moderator->attachPermission($permission);
     /**
      * Papers
      */
     $permission = new Permission();
     $permission->name = 'create-papers';
     $permission->display_name = 'Create Papers';
     // optional
     $permission->description = 'Creating Papers in The System';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $moderator->attachPermission($permission);
     $registered->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'update-papers';
     $permission->display_name = 'Update Papers';
     // optional
     $permission->description = 'Updating Papers in the System';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $moderator->attachPermission($permission);
     $registered->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'delete-papers';
     $permission->display_name = 'Delete Papers';
     // optional
     $permission->description = 'Deleting Papers from the System';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $moderator->attachPermission($permission);
     /**
      * Questions
      */
     $permission = new Permission();
     $permission->name = 'create-question';
     $permission->display_name = 'Create Question';
     // optional
     $permission->description = 'Create Question in the System';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $moderator->attachPermission($permission);
     $registered->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'update-question';
     $permission->display_name = 'Update Question';
     // optional
     $permission->description = 'Update Questions in the System';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $moderator->attachPermission($permission);
     $registered->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'delete-question';
     $permission->display_name = 'Delete Question';
     // optional
     $permission->description = 'Deleting Question from the System';
//.........这里部分代码省略.........
开发者ID:jhcict,项目名称:mcq,代码行数:101,代码来源:SystemSeeder.php

示例6: reset

 /**
  * Reset Role, Permissions & Users
  *
  * @param  $role
  * @return void
  */
 public function reset($role)
 {
     $commandBullet = '  -> ';
     // The Old Role
     $originalRole = Role::where('name', $role['name'])->first();
     if ($originalRole) {
         Role::where('id', $originalRole->id)->update(['name' => $role['name'] . '__remove']);
     }
     // The New Role
     $newRole = new Role();
     $newRole->name = $role['name'];
     if (isset($role['display_name'])) {
         $newRole->display_name = $role['display_name'];
     }
     // optional
     if (isset($role['description'])) {
         $newRole->description = $role['description'];
     }
     // optional
     $newRole->save();
     $this->command->info($commandBullet . "Created {$role['name']} role");
     // Set the Permissions (if they exist)
     $pcount = 0;
     if (!empty($role['permissions'])) {
         foreach ($role['permissions'] as $permission_name) {
             $permission = $this->permissions($permission_name);
             if ($permission === false || !$permission_name) {
                 $this->command->error($commandBullet . "Failed to attach permission '{$permission_name}'. It does not exist");
                 continue;
             }
             $newPermission = Permission::where('name', $permission_name)->first();
             if (!$newPermission) {
                 $newPermission = new Permission();
                 $newPermission->name = key($permission);
                 if (isset($permission['display_name'])) {
                     $newPermission->display_name = $permission['display_name'];
                 }
                 // optional
                 if (isset($permission['description'])) {
                     $newPermission->description = $permission['description'];
                 }
                 // optional
                 $newPermission->save();
             }
             $newRole->attachPermission($newPermission);
             $pcount++;
         }
     }
     $this->command->info($commandBullet . "Attached {$pcount} permissions to {$role['name']} role");
     // Update old records
     if ($originalRole) {
         $userCount = 0;
         $RoleUsers = DB::table(Config::get('entrust.role_user_table'))->where('role_id', $originalRole->id)->get();
         foreach ($RoleUsers as $user) {
             $u = User::where('id', $user->user_id)->first();
             $u->attachRole($newRole);
             $userCount++;
         }
         $this->command->info($commandBullet . "Updated role attachment for {$userCount} users");
         Role::where('id', $originalRole->id)->delete();
         // will also remove old role_user records
         $this->command->info($commandBullet . "Removed the original {$role['name']} role");
     }
 }
开发者ID:davidvarney,项目名称:tagmovement,代码行数:70,代码来源:RolesAndPermissionsSeeder.php


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