Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
add syncPermissions() method for user and for role
Browse files Browse the repository at this point in the history
  • Loading branch information
webkonstantin committed Dec 17, 2015
1 parent 6687ccb commit 5a5ad9d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Bican/Roles/Contracts/HasRoleAndPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public function detachRole($role);
*/
public function detachAllRoles();

/**
* Sync roles for a user.
*
* @param array|\Bican\Roles\Models\Role[]|\Illuminate\Database\Eloquent\Collection $roles
* @return array
*/
public function syncRoles($roles);

/**
* Get role level of a user.
*
Expand Down Expand Up @@ -170,4 +178,12 @@ public function detachPermission($permission);
* @return int
*/
public function detachAllPermissions();

/**
* Sync permissions for a user.
*
* @param array|\Bican\Roles\Models\Permission[]|\Illuminate\Database\Eloquent\Collection $permissions
* @return array
*/
public function syncPermissions($permissions);
}
8 changes: 8 additions & 0 deletions src/Bican/Roles/Contracts/RoleHasRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ public function detachPermission($permission);
* @return int
*/
public function detachAllPermissions();

/**
* Sync permissions for a role.
*
* @param array|\Bican\Roles\Models\Permission[]|\Illuminate\Database\Eloquent\Collection $permissions
* @return array
*/
public function syncPermissions($permissions);
}
13 changes: 13 additions & 0 deletions src/Bican/Roles/Traits/HasRoleAndPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,19 @@ public function detachAllPermissions()
return $this->userPermissions()->detach();
}

/**
* Sync permissions for a user.
*
* @param array|\Bican\Roles\Models\Permission[]|\Illuminate\Database\Eloquent\Collection $permissions
* @return array
*/
public function syncPermissions($permissions)
{
$this->permissions = null;

return $this->permissions()->sync($permissions);
}

/**
* Check if pretend option is enabled.
*
Expand Down
11 changes: 11 additions & 0 deletions src/Bican/Roles/Traits/RoleHasRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,15 @@ public function detachAllPermissions()
{
return $this->permissions()->detach();
}

/**
* Sync permissions for a role.
*
* @param array|\Bican\Roles\Models\Permission[]|\Illuminate\Database\Eloquent\Collection $permissions
* @return array
*/
public function syncPermissions($permissions)
{
return $this->permissions()->sync($permissions);
}
}

0 comments on commit 5a5ad9d

Please sign in to comment.