An opinionated boilerplate generator. Generate boilerplates like repositories, routes, events, api docs and much more!
This project is still under development and unusable.
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 [
];
First, define a schema.php
file in the database
folder. You can overwrite the default file path in
the boilerplate.php
config file.
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',
],
],
],
];
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.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email freek@acadea.be instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.