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);
     return $this->view(static::VIEW_PERMISSIONS, ['role' => $role, 'permissions' => Permission::all()]);
 }
 public function __construct($user)
 {
     foreach (RolePermission::where('profileid', $user->getAttribute("profileid"))->get() as $value) {
         $this->roles[$value->getAttribute("action")] = $value->getAttribute("permission");
     }
 }