acadea / boilerplate
An opinionated Laravel boilerplate generator. Generate boilerplates like repositories, routes, events, api docs and much more!
Fund package maintenance!
acadea
acadea.io/open-source/support-us
Requires
- php: ^7.4
- acadea/fixer: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
- spatie/phpunit-watcher: ^1.23
This package is auto-updated.
Last update: 2024-11-11 15:14:05 UTC
README
An opinionated boilerplate generator. Generate boilerplates like repositories, routes, events, api docs and much more!
NOTE
This project is still under development and unusable.
Installation
You can install the package via composer:
composer require acadea/boilerplate
You can publish and run the migrations with:
php artisan vendor:publish --provider="Acadea\Boilerplate\BoilerplateServiceProvider" --tag="migrations" php artisan migrate
You can publish the config file with:
php artisan vendor:publish --provider="Acadea\Boilerplate\BoilerplateServiceProvider" --tag="config"
This is the contents of the published config file:
return [
];
Usage
First, define a schema.php
file in the database
folder. You can overwrite the default file path in
the boilerplate.php
config file.
Structure of schema.php
Must follow convention Pivot: post_tag
Model name must be singular and snake-cased
return [ 'post' => [ 'title' => [ // any column type supported by eloquent // https://laravel.com/docs/8.x/migrations#available-column-types 'type' => 'string', // attributes are column modifier // https://laravel.com/docs/8.x/migrations#column-modifiers 'attributes' => [ // put a flat string if no argument to pass to the modifier 'nullable', // if we need to pass arguments to the modifier // array key is the modifier method, value should be an array of arguments value to pass to the modifier 'default' => ['some post'], ], ], 'body' => [ 'type' => 'mediumText', 'attributes' => ['nullable'], ], 'book_author_id' => [ 'type' => 'foreignId', 'foreign' => [ 'references' => 'id', 'on' => 'book_authors', ], ], // will add belongsToMany relationship to model 'tags' => [ 'type' => 'pivot', 'pivot' => [ 'table' => 'post_tag', 'related_key' => 'post_id', 'foreign_key' => 'tag_id', ] ] ], // PIVOT TABLE // add 'pivot:' before table name to create pivot migration 'pivot:post_tag' => [ 'post_id' => [ // to set this column as primary key in the pivot table 'primary' => true, 'type' => 'foreignId', 'attributes' => [ 'index' ], 'foreign' => [ 'references' => 'id', 'on' => 'posts', ], ], 'tag_id' => [ 'primary' => true, 'type' => 'foreignId', 'attributes' => [ 'index' ], 'foreign' => [ 'references' => 'id', 'on' => 'tags', ], ], ], ];
API routes
This package will bootstrap all the boilerplate routes for you.
However, you will need to include the following code in api.php
for the boilerplate to work correctly.
Route::group([ 'namespace' => 'Api', 'as' => 'api.', 'middleware' => [ 'auth:sanctum', ], ], function () { require __DIR__ . '/api/v1.php'; });
Alternatively, you can run the boilerplate:install
command, this package will overwrite the api.php
file for you.
Caveats
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email freek@acadea.be instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.