diff --git a/src/Permissions.php b/src/Permissions.php index c8741ed..69c1d68 100644 --- a/src/Permissions.php +++ b/src/Permissions.php @@ -20,6 +20,8 @@ class Permissions protected string $panel = 'user'; + protected array $excludePermissions = []; + public function __construct() { $this->splitter = config('permission-generator.route-name-splitter-needle'); @@ -37,6 +39,13 @@ public function panel(string $panel) return $this; } + public function exclude(array $permissions) + { + $this->excludePermissions = $permissions; + + return $this; + } + public function fromResources(array $resources) { if ($this->hasCachedPermissions()) { @@ -59,7 +68,7 @@ public function fromRoutes() return $this; } - $routePermissionGenerator = (new RoutePermissionGenerator($this->panel))->generate(); + $routePermissionGenerator = (new RoutePermissionGenerator($this->panel))->exclude($this->excludePermissions)->generate(); $this->permissions = $routePermissionGenerator['permissions']; $this->onlyPermissionsNames = $routePermissionGenerator['only_permission_names']; diff --git a/src/Services/RoutePermissionGenerator.php b/src/Services/RoutePermissionGenerator.php index 63620f2..015711f 100644 --- a/src/Services/RoutePermissionGenerator.php +++ b/src/Services/RoutePermissionGenerator.php @@ -14,11 +14,26 @@ class RoutePermissionGenerator private string $panel; + protected array $excludePermissions = []; + public function __construct(string $panel = 'user') { $this->panel = $panel; } + /** + * Exclude specific permissions from the permission list. + * + * @param array $permissions exclude permissions on demand. + * @return $this + */ + public function exclude(array $permissions) + { + $this->excludePermissions = $permissions; + + return $this; + } + public function generate() { $this->permissionGenerateControllers = config( @@ -35,6 +50,8 @@ public function generate() $globalExcludedRoutes = config("permission-generator.exclude-routes.panels.{$this->panel}", []); + $excludedRoutes = array_merge($globalExcludedRoutes, $this->excludePermissions); + $routes = Route::getRoutes(); $onlyPermissionNames = []; @@ -45,7 +62,7 @@ public function generate() $routeName = $route->getName(); // exclude routes which defined in the config - if (in_array($routeName, $globalExcludedRoutes)) { + if (in_array($routeName, $excludedRoutes)) { continue; }