Stubby for Laravel (Not Quite Ready Yet)
Customizable stubs for things artisans make:
This package lets you edit the stubs used to generate lots of things you'd normally create using Laravel's built in make: commands. Additionally, Stubby lets you automatically create tests for your new creations.
Installation
You can install the package via composer:
composer require edgrosvenor/stubby --dev
Creating Something Great
php artisan stubby:make {component} {name?}
If you don't provide a name, you'll be prompted for one. Here's what you can create (more to come):
Component | Description | Test | Destination |
---|---|---|---|
controller | A vanilla web controller | feature | App/Http/Controllers |
api | A vanilla api controller | feature | App/Http/Controllers/Api |
resource | A vanilla resource controller | feature | App/Http/Controllers/Api |
invokable | An invokable web controller | feature | App/Http/Controllers |
command | A Laravel command | unit | App/Console/Commands |
action | An action class | unit | App/Actions |
livewire | A Livewire component | either / both | See Livewire Docs |
test | An integration test | Too meta | tests/feature |
unit | A unit test | Way too meta | tests/unit |
You can edit the type of test created for each component as well as its destination (except for Livewire) by publishing and editing Stubby's configuration.
Editing Stubs
You can edit the stubs that create each component and the stubs for each component's tests. They're stored as blade templates, which you can publish and then edit to your liking. One thing to note is that I prepend the PHP open tag when creating the file so it's not in the blade template itself. I didn't want to work around the errors that were caused by it being in the template. So don't try to add the missing <?php
to the top of the stubs.
Branching Out
I developed this package for use at my little two man shop. We like to create feature branches for the components we generate. When we've done the red / green / refactor thing we push up the branch and submit a pull request for the other to glance at and merge. If feature branches fit with your workflow, you can automatically check out a new branch whenever creating a new component by adding --branch
to the command. Or you can edit the config to automatically create feature branches for certain types of components.
Future Plans
I wrote this package to address a few pain points I experience at work. Other pain points for me that I'd like to address here are:
- Routing - I hate having to open the route files when I create new controllers to add the routes. I want to add a set of questions to the command when creating a controller to interactively populate the appropriate routes file.
- Views - I always use invokable controllers in web routes and each controller has exactly one view. I want to set up a config option that would automatically create a view for invokable controllers and add the
return view('new_view_name')
directive to the __invoke() method.
What Can You Add?
Is there something you can think of that could save artisans some keystrokes every day? I welcome pull requests and even just feature requests if you prefer.
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email ed.grosvenor@wickedviral.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.