blackfyre/blueprint-nova-addon

资助包维护!
Naoray

v1.5.8 2021-04-01 19:51 UTC

README

Build Status Total Downloads

📣 向 Jason McCreary 致敬,他的 Blueprint 包为这个小插件奠定了基础。感谢 Jason 🙌

安装此插件后,您可以使用 php artisan blueprint:build 命令生成 Nova 资源。

安装

您可以通过 composer 安装此包和 Blueprint

composer require --dev blackfyre/blueprint-nova-addon

⚠️ 为了进行资源生成,您需要安装 laravel nova

用法

请参考 Blueprint 的基本用法 以开始使用。之后,您可以运行 blueprint:build 命令来自动生成 Nova 资源。您可以使用下面的示例 draft.yaml 文件来了解其易用性。

# draft.yaml
models:
  Post:
    author_id: id foreign:users
    title: string:400
    content: longtext
    published_at: nullable timestamp
    relationships:
      HasMany: Comment

  Comment:
    post_id: id foreign
    content: longtext
    published_at: nullable timestamp

从这些 13 行 YAML 中,此插件将生成 2 个 Nova 资源,其中预填充了 14 个字段。

// App/Nova/Comment.php
public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        Textarea::make('Content')
            ->rules('required', 'string'),

        DateTime::make('Published at'),

        BelongsTo::make('Post'),

        DateTime::make('Created at'),
        DateTime::make('Updated at'),
    ];
}

// App/Nova/Post.php
public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        Text::make('Title')
            ->rules('required', 'string', 'max:400'),

        Textarea::make('Content')
            ->rules('required', 'string'),

        DateTime::make('Published at'),

        BelongsTo::make('Author', 'author', User::class),

        HasMany::make('Comments'),

        DateTime::make('Created at'),
        DateTime::make('Updated at'),
    ];
}

配置

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

php artisan vendor:publish --tag=nova_blueprint

时间戳字段

要将所有 Nova 资源的时间戳字段生成设置为 false,请设置此选项。

测试

composer test

变更日志

有关最近更改的更多信息,请参阅 变更日志

贡献

有关详细信息,请参阅 贡献指南

安全性

如果您发现任何与安全性相关的问题,请通过电子邮件 krishan.koenig@gmail.com 而不是使用问题跟踪器。

鸣谢

许可协议

MIT 许可协议 (MIT)。有关更多信息,请参阅 许可文件