Installation
composer require larastarscn/workbench
Add to config/app.php:
'providers' => [
Larastarscn\Workbench\WorkbenchServiceProvider::class,
],
Register the command in app/Console/Kernel.php:
protected $commands = [
\Larastarscn\Workbench\Console\WorkbenchMakeCommand::class,
];
Publish Config
php artisan vendor:publish --provider="Larastarscn\Workbench\WorkbenchServiceProvider"
Update config/workbench.php with your author details (e.g., name, email, github).
First Use Case Generate a basic package structure:
php artisan workbench vendor/package-name
Example:
php artisan workbench larastarscn/test-package
Package Scaffolding
php artisan workbench vendor/package to generate:
src/, config/, tests/, etc.).ServiceProvider, Facade, Config, README.md).config/workbench.php (e.g., disable certain files like tests/).Integration with Package Development
composer.json as a template for your package.src/ directory for core logic (e.g., classes, traits, interfaces).php artisan vendor:publish --tag="config"
Extending Templates
php artisan vendor:publish --tag="workbench-templates"
resources/views/vendor/workbench/ (e.g., config.stub, readme.stub).Automating Releases
README.md and CHANGELOG.md stubs as starting points.post-create scripts in composer.json to run tests or linting:
"scripts": {
"post-create-package": [
"@php artisan test",
"@php artisan lint"
]
}
Configuration Overrides
config/workbench.php will default to empty author fields, causing warnings in generated files.php artisan vendor:publish after installation.Namespace Conflicts
yourcompany/unique-package).Template Path Issues
resources/views/vendor/workbench/ must match the stub names exactly (e.g., config.stub).config/workbench.php under templates.Permission Errors
php artisan workbench in a directory without write permissions will fail.sudo or ensure proper permissions for the target directory.Dry Run Mode
Use --dry-run to preview changes without writing files:
php artisan workbench vendor/package --dry-run
Verbose Output Enable debug mode for detailed logs:
php artisan workbench vendor/package --verbose
Custom Commands
Extend the WorkbenchMakeCommand to add pre/post-creation hooks:
// app/Console/Commands/CustomWorkbenchCommand.php
use Larastarscn\Workbench\Console\WorkbenchMakeCommand;
class CustomWorkbenchCommand extends WorkbenchMakeCommand {
protected function getStubContents() {
// Modify stubs or add logic here
}
}
Dynamic Templates Use Laravel’s blade syntax in stubs to inject dynamic data:
// resources/views/vendor/workbench/config.stub
<?php echo '<?php'; ?>
return [
'author' => '@authorName',
'version' => '@packageVersion',
];
Post-Creation Scripts
Add scripts to composer.json to automate post-generation tasks:
"scripts": {
"post-create-package": [
"php artisan workbench:post-create vendor/package"
]
}
Template Organization
Group related stubs (e.g., src/, tests/) in subdirectories within resources/views/vendor/workbench/ for clarity.
CI/CD Integration Use Workbench in CI pipelines to scaffold packages before running tests:
# .github/workflows/package-ci.yml
steps:
- run: php artisan workbench vendor/package
- run: composer test
Git Ignore
Add generated files to .gitignore if they’re not part of the package’s public API:
/vendor
/node_modules
/tests/
How can I help you explore Laravel packages today?