public function run()
 {
     $this->command->info('Seeding permission groups and relationships.');
     PermissionGroupAssignment::truncate();
     foreach ($this->slugs() as $slug) {
         $permissionGrouppermissions = $slug['permissions'];
         unset($slug['permissions']);
         $permissionGroup = PermissionGroup::firstOrNew(['group_name' => $slug['group_name']]);
         $permissionGroup->group_name = $slug['group_name'];
         $permissionGroup->display_order = $slug['display_order'];
         $permissionGroup->is_system_only = !!(isset($slug['is_system_only']) ? $slug['is_system_only'] : false);
         $permissionGroup->is_account_only = !!(isset($slug['is_account_only']) ? $slug['is_account_only'] : false);
         $permissionGroup->save();
         foreach ($permissionGrouppermissions as $permissionGroupIndex => $permissionGroupPermission) {
             $permissionGrouppermissionModel = PermissionGroupAssignment::firstOrNew(['permission_id' => $permissionGroupPermission, 'permission_group_id' => $permissionGroup->permission_group_id]);
             if ($permissionGrouppermissionModel->exists) {
                 PermissionGroupAssignment::where(['permission_id' => $permissionGroupPermission, 'permission_group_id' => $permissionGroup->permission_group_id])->update(['display_order' => $permissionGroupIndex * 10]);
             } else {
                 $permissionGrouppermissionModel->display_order = $permissionGroupIndex * 10;
                 $permissionGrouppermissionModel->save();
             }
             $permissionGrouppermissionModels[] = $permissionGrouppermissionModel;
         }
     }
 }
 public function patchIndex(Role $role)
 {
     if (!$this->user->canAdminRoles() || !$this->user->canAdminPermissions()) {
         return abort(403);
     }
     $input = Input::all();
     $permissions = Permission::all();
     $rolePermissions = [];
     $nullPermissions = [];
     foreach ($permissions as $permission) {
         if ($this->user->can($permission->permission_id)) {
             $nullPermissions[] = $permission->permission_id;
             foreach ($input as $permission_id => $permission_value) {
                 $permission_id = str_replace("_", ".", $permission_id);
                 if ($permission->permission_id == $permission_id) {
                     switch ($permission_value) {
                         case "allow":
                         case "deny":
                             $rolePermissions[] = ['role_id' => $role->role_id, 'permission_id' => $permission_id, 'value' => $permission_value == "allow"];
                             break;
                     }
                     break;
                 }
             }
         }
     }
     RolePermission::where(['role_id' => $role->role_id])->whereIn('permission_id', $nullPermissions)->delete();
     RolePermission::insert($rolePermissions);
     $permission_groups = PermissionGroup::withPermissions()->get();
     Event::fire(new RoleWasModified($role));
     return $this->view(static::VIEW_PERMISSIONS, ['role' => $role, 'groups' => $permission_groups]);
 }
 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function getIndex(Role $role)
 {
     if (!$this->user->canAdminRoles() || !$this->user->canAdminPermissions()) {
         return abort(403);
     }
     $permission_groups = PermissionGroup::withPermissions()->get();
     return $this->view(static::VIEW_PERMISSIONS, ['role' => $role, 'groups' => $permission_groups]);
 }