From 936957481dadadc217f8fb669058113099d2d17b Mon Sep 17 00:00:00 2001 From: Brian Verschoore Date: Sat, 22 Mar 2025 09:44:31 +0100 Subject: [PATCH 1/2] Add option to publish stub files --- README.md | 6 ++++++ src/Commands/AbilityMakeCommand.php | 4 +++- src/Commands/DefinedRoleMakeCommand.php | 4 +++- src/RbacServiceProvider.php | 10 ++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 138a531..f9aff89 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,12 @@ return [ ]; ``` +You can publish the stub files with: + +```bash +php artisan vendor:publish --tag="rbac-stubs" +``` + ## Usage ```bash diff --git a/src/Commands/AbilityMakeCommand.php b/src/Commands/AbilityMakeCommand.php index 883240d..67b99f2 100644 --- a/src/Commands/AbilityMakeCommand.php +++ b/src/Commands/AbilityMakeCommand.php @@ -26,7 +26,9 @@ class AbilityMakeCommand extends GeneratorCommand */ protected function getStub() { - return __DIR__.'/../../stubs/ability.stub'; + return file_exists($customPath = base_path('/stubs/ability.stub')) + ? $customPath + : __DIR__.'/../../stubs/ability.stub'; } /** diff --git a/src/Commands/DefinedRoleMakeCommand.php b/src/Commands/DefinedRoleMakeCommand.php index 22f791d..f6bf224 100644 --- a/src/Commands/DefinedRoleMakeCommand.php +++ b/src/Commands/DefinedRoleMakeCommand.php @@ -25,7 +25,9 @@ class DefinedRoleMakeCommand extends GeneratorCommand */ protected function getStub() { - return __DIR__.'/../../stubs/defined-role.stub'; + return file_exists($customPath = base_path('/stubs/defined-role.stub')) + ? $customPath + : __DIR__.'/../../stubs/defined-role.stub'; } /** diff --git a/src/RbacServiceProvider.php b/src/RbacServiceProvider.php index 60dadab..af2c1cf 100644 --- a/src/RbacServiceProvider.php +++ b/src/RbacServiceProvider.php @@ -23,6 +23,16 @@ public function configurePackage(Package $package): void ]); } + public function packageBooted() + { + parent::packageBooted(); + + $this->publishes([ + __DIR__.'/../stubs/ability.stub' => base_path('stubs/ability.stub'), + __DIR__.'/../stubs/defined-role.stub' => base_path('stubs/defined-role.stub'), + ], ['rbac-stubs', 'stubs']); + } + /** * @return void */ From 7192eb3ce2afb34134a070258b5eed1e443948fb Mon Sep 17 00:00:00 2001 From: Brian Verschoore Date: Sat, 22 Mar 2025 09:50:27 +0100 Subject: [PATCH 2/2] Fix styling --- src/RbacServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RbacServiceProvider.php b/src/RbacServiceProvider.php index af2c1cf..a7ce877 100644 --- a/src/RbacServiceProvider.php +++ b/src/RbacServiceProvider.php @@ -28,7 +28,7 @@ public function packageBooted() parent::packageBooted(); $this->publishes([ - __DIR__.'/../stubs/ability.stub' => base_path('stubs/ability.stub'), + __DIR__.'/../stubs/ability.stub' => base_path('stubs/ability.stub'), __DIR__.'/../stubs/defined-role.stub' => base_path('stubs/defined-role.stub'), ], ['rbac-stubs', 'stubs']); }