Skip to content
This repository has been archived by the owner on Apr 5, 2019. It is now read-only.

Commit

Permalink
Clear permission cache after attach role and permission
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricky-rick committed Jan 26, 2017
1 parent d516a50 commit 3ea11d2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Traits/HasRoleAndPermission.php
Expand Up @@ -122,7 +122,11 @@ public function checkRole($role)
*/
public function attachRole($role)
{
return (!$this->getRoles()->contains($role)) ? $this->roles()->attach($role) : true;
if ($this->getRoles()->contains($role)) {
return true;
}
$this->roles = null;
return $this->roles()->attach($role);
}

/**
Expand Down Expand Up @@ -332,7 +336,11 @@ protected function isAllowed($providedPermission, Model $entity)
*/
public function attachPermission($permission)
{
return (!$this->getPermissions()->contains($permission)) ? $this->userPermissions()->attach($permission) : true;
if ($this->getPermissions()->contains($permission)) {
return true;
}
$this->permissions = null;
return $this->userPermissions()->attach($permission);
}

/**
Expand Down

0 comments on commit 3ea11d2

Please sign in to comment.