Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jul 23, 2016
1 parent 5eca21c commit b817bae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
19 changes: 4 additions & 15 deletions src/Traits/HasPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ trait HasPermissions
*/
public function givePermissionTo(...$permissions)
{
collect($permissions)
$permissions = collect($permissions)
->flatten()
->map(function ($permission) {
return $this->getStoredPermission($permission);
})
->each(function (Permission $permission) {
return $this->permissions()->save($permission);
});

$this->permissions()->saveMany($permissions);

$this->forgetCachedPermissions();

return $this;
Expand All @@ -40,17 +39,7 @@ public function syncPermissions(...$permissions)
{
$this->permissions()->detach();

collect($permissions)
->flatten()
->map(function ($permission) {
return $this->getStoredPermission($permission);
})->each(function (Permission $permission) {
$this->permissions()->save($permission);
});

$this->forgetCachedPermissions();

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

/**
Expand Down
17 changes: 4 additions & 13 deletions src/Traits/HasRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ public function permissions()
*/
public function assignRole(...$roles)
{
collect($roles)
$roles = collect($roles)
->flatten()
->map(function ($role) {
return $this->getStoredRole($role);
})
->each(function (Role $role) {
return $this->roles()->save($role);
});

$this->roles()->saveMany($roles);

$this->forgetCachedPermissions();

return $this;
Expand All @@ -80,15 +79,7 @@ public function syncRoles(...$roles)
{
$this->roles()->detach();

collect($roles)
->flatten()
->map(function ($role) {
return $this->getStoredRole($role);
})->each(function (Role $role) {
$this->roles()->save($role);
});

return $this;
return $this->assignRole($roles);
}

/**
Expand Down

0 comments on commit b817bae

Please sign in to comment.