acadea/boilerplate

一个有观点的Laravel模板生成器。生成诸如存储库、路由、事件、API文档等模板!

v0.2.0 2021-04-21 03:50 UTC

This package is auto-updated.

Last update: 2024-09-11 14:53:41 UTC


README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

一个有观点的模板生成器。生成存储库、路由、事件、API文档等模板!

注意

此项目仍在开发中,不可使用。

安装

您可以通过composer安装此包

composer require acadea/boilerplate

您可以使用以下命令发布和运行迁移

php artisan vendor:publish --provider="Acadea\Boilerplate\BoilerplateServiceProvider" --tag="migrations"
php artisan migrate

您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="Acadea\Boilerplate\BoilerplateServiceProvider" --tag="config"

这是已发布配置文件的内容

return [
];

使用方法

首先,在database文件夹中定义一个schema.php文件。您可以在boilerplate.php配置文件中覆盖默认文件路径。

schema.php的结构

必须遵循约定 Pivot: post_tag

模型名称必须是单数且蛇形

return [
    'post' => [
        'title' => [
            // any column type supported by eloquent
            // https://laravel.net.cn/docs/8.x/migrations#available-column-types
            'type' => 'string', 
            // attributes are column modifier  
            // https://laravel.net.cn/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路由

此包将为您启动所有模板路由。

然而,您需要将以下代码包含在api.php中,以便模板可以正确工作。

Route::group([
    'namespace' => 'Api',
    'as' => 'api.',
    'middleware' => [
        'auth:sanctum',
    ],
], function () {
    require __DIR__ . '/api/v1.php';
});

或者,您可以运行boilerplate:install命令,此包将为您覆盖api.php文件。

注意事项

测试

composer test

更新日志

请参阅更新日志以获取有关最近更改的更多信息。

贡献

请参阅贡献指南以获取详细信息。

安全

如果您发现任何安全问题,请通过电子邮件freek@acadea.be联系,而不是使用问题跟踪器。

鸣谢

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。