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..a7ce877 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 */