Skip to content

Add option to publish stub files #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ return [
];
```

You can publish the stub files with:

```bash
php artisan vendor:publish --tag="rbac-stubs"
```

## Usage

```bash
Expand Down
4 changes: 3 additions & 1 deletion src/Commands/AbilityMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Commands/DefinedRoleMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/RbacServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down