Skip to content

Commit

Permalink
Finished roles tests
Browse files Browse the repository at this point in the history
  • Loading branch information
santigarcor committed Feb 14, 2017
1 parent 2e4fe7b commit 7197458
Show file tree
Hide file tree
Showing 3 changed files with 399 additions and 11 deletions.
23 changes: 15 additions & 8 deletions src/Laratrust/Traits/LaratrustRoleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Cache;
use InvalidArgumentException;

trait LaratrustRoleTrait
{
Expand Down Expand Up @@ -137,7 +138,7 @@ public function syncPermissions($permissions)
$changes = $this->permissions()->sync($permissions);
$this->flushCache();

return $changes;
return $this;
}

/**
Expand Down Expand Up @@ -193,8 +194,12 @@ public function attachPermissions($permissions)
*
* @return void
*/
public function detachPermissions($permissions)
public function detachPermissions($permissions = null)
{
if (!$permissions) {
$permissions = $this->permissions()->get();
}

foreach ($permissions as $permission) {
$this->detachPermission($permission);
}
Expand All @@ -218,13 +223,15 @@ public function flushCache()
private function getIdFor($permission)
{
if (is_object($permission)) {
$permission = $permission->getKey();
return $permission->getKey();
} elseif (is_int($permission)) {
return $permission;
} elseif (is_array($permission)) {
return $permission['id'];
}

if (is_array($permission)) {
$permission = $permission['id'];
}

return $permission;
throw new InvalidArgumentException(
'getIdFor function only accepts an integer, a Model object or an array with an "id" key'
);
}
}

0 comments on commit 7197458

Please sign in to comment.