File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ class Permissions
2020
2121 protected string $ panel = 'user ' ;
2222
23+ protected array $ excludePermissions = [];
24+
2325 public function __construct ()
2426 {
2527 $ this ->splitter = config ('permission-generator.route-name-splitter-needle ' );
@@ -37,6 +39,13 @@ public function panel(string $panel)
3739 return $ this ;
3840 }
3941
42+ public function exclude (array $ permissions )
43+ {
44+ $ this ->excludePermissions = $ permissions ;
45+
46+ return $ this ;
47+ }
48+
4049 public function fromResources (array $ resources )
4150 {
4251 if ($ this ->hasCachedPermissions ()) {
@@ -59,7 +68,7 @@ public function fromRoutes()
5968 return $ this ;
6069 }
6170
62- $ routePermissionGenerator = (new RoutePermissionGenerator ($ this ->panel ))->generate ();
71+ $ routePermissionGenerator = (new RoutePermissionGenerator ($ this ->panel ))->exclude ( $ this -> excludePermissions )-> generate ();
6372
6473 $ this ->permissions = $ routePermissionGenerator ['permissions ' ];
6574 $ this ->onlyPermissionsNames = $ routePermissionGenerator ['only_permission_names ' ];
Original file line number Diff line number Diff line change @@ -14,11 +14,26 @@ class RoutePermissionGenerator
1414
1515 private string $ panel ;
1616
17+ protected array $ excludePermissions = [];
18+
1719 public function __construct (string $ panel = 'user ' )
1820 {
1921 $ this ->panel = $ panel ;
2022 }
2123
24+ /**
25+ * Exclude specific permissions from the permission list.
26+ *
27+ * @param array $permissions exclude permissions on demand.
28+ * @return $this
29+ */
30+ public function exclude (array $ permissions )
31+ {
32+ $ this ->excludePermissions = $ permissions ;
33+
34+ return $ this ;
35+ }
36+
2237 public function generate ()
2338 {
2439 $ this ->permissionGenerateControllers = config (
@@ -35,6 +50,8 @@ public function generate()
3550
3651 $ globalExcludedRoutes = config ("permission-generator.exclude-routes.panels. {$ this ->panel }" , []);
3752
53+ $ excludedRoutes = array_merge ($ globalExcludedRoutes , $ this ->excludePermissions );
54+
3855 $ routes = Route::getRoutes ();
3956
4057 $ onlyPermissionNames = [];
@@ -45,7 +62,7 @@ public function generate()
4562 $ routeName = $ route ->getName ();
4663
4764 // exclude routes which defined in the config
48- if (in_array ($ routeName , $ globalExcludedRoutes )) {
65+ if (in_array ($ routeName , $ excludedRoutes )) {
4966 continue ;
5067 }
5168
You can’t perform that action at this time.
0 commit comments