コード例 #1
0
 public function update($data, $dataPerm, $role)
 {
     $role->update($data);
     $listIds = $dataPerm["permissions"];
     if ($role->permissions->count()) {
         $role->detachAllPermissions();
         foreach ($listIds as $key => $value) {
             $role->attachPermission(Permission::find($value));
         }
     }
     if ($role->permissions->count() == 0 && count(\Input::get('permissions')) > 0) {
         foreach ($listIds as $key => $value) {
             $role->attachPermission(Permission::find($value));
         }
     }
 }
コード例 #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     if (!Permission::find(1)) {
         $permissionsAdmin = array('Manage Pages', 'Manage Settings', 'Manage Roles', 'Manage Permissions', 'See all Sales', 'Manage Customers', 'Manage Sells', 'Manage Categories', 'Set Prices', 'Manage Profile', 'Buy Goods', 'Share Goods');
         foreach ($permissionsAdmin as $permission) {
             $perm = Permission::updateOrCreate(['name' => $permission, 'display_name' => $permission, 'description' => $permission]);
             $roleAdmin = Role::find(1);
             $roleAdmin->attachPermission($perm, new Role());
         }
         $listIds = Permission::all()->lists('id');
         $roleManager = Role::find(2);
         foreach ($listIds as $key => $permission) {
             if ($key >= 5 && $key <= 8) {
                 $roleManager->attachPermission(Permission::find($permission));
             }
         }
         $roleCustomer = Role::find(3);
         foreach ($listIds as $key => $permission) {
             if ($key >= 9 && $key <= 11) {
                 $roleCustomer->attachPermission(Permission::find($permission));
             }
         }
     }
 }