Skip to content

Commit

Permalink
add: wildcard permission (*)
Browse files Browse the repository at this point in the history
  • Loading branch information
uyab committed Sep 22, 2019
1 parent 67e0dcb commit 6211fa0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function syncPermission(array $permissions)
{
$ids = collect($permissions)->transform(function ($permission) {
if (is_numeric($permission)) {
return (int)$permission;
return (int) $permission;
} elseif (is_string($permission)) {
$permissionObject = app(config('laravolt.acl.models.permission'))->firstOrCreate(['name' => $permission]);

Expand All @@ -54,5 +54,4 @@ public function syncPermission(array $permissions)

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

}
15 changes: 13 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ public function register()
/**
* Application is booting
* @see http://laravel.com/docs/master/providers#the-boot-method
* @param Gate $gate
* @param Gate $gate
*/
public function boot(Gate $gate)
{
$this->registerConfigurations();

$this->registerWildcardPermission();

$this->registerAcl($gate);

if ($this->app->runningInConsole()) {
Expand Down Expand Up @@ -123,11 +125,20 @@ protected function registerCommands()

/**
* Loads a path relative to the package base directory
* @param string $path
* @param string $path
* @return string
*/
protected function packagePath($path = '')
{
return sprintf("%s/../%s", __DIR__, $path);
}

protected function registerWildcardPermission()
{
\Illuminate\Support\Facades\Gate::before(function (HasRoleAndPermission $user) {
if ($user->hasPermission('*')) {
return true;
}
});
}
}

0 comments on commit 6211fa0

Please sign in to comment.