pedrosantiago/nova-grid

添加列以创建和更新资源

dev-master 2019-10-15 02:26 UTC

README

这是一个用于Laravel Nova管理面板的工具,允许您为资源创建基于网格的布局。

安装

您可以通过composer安装此包

composer require jobcerto/nova-grid

然后,您需要在NovaServiceProvider.php中注册此工具

use Jobcerto\NovaGrid\NovaGrid;

...

/**
 * Get the tools that should be listed in the Nova sidebar.
 *
 * @return array
 */
public function tools()
{
    return [
        // other tools
        new NovaGrid,
    ];
}

使用此工具

  • 设置工具后,现在您所有的字段都可以访问到meta属性size,其值是tailwind类的大小。

示例

public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            Text::make('Name')
                ->size('w-1/3'),

            Select::make('Type')
                ->size('w-1/3')
                ->options(UserType::toSelectArray()),

            Text::make('Email')
                ->size('w-1/3')
                ->sortable()
                ->rules('required', 'email', 'max:254')
                ->creationRules('unique:users,email')
                ->updateRules('unique:users,email,{{resourceId}}', 'sometimes'),

            Password::make('Password')
                ->size('w-1/3')
                ->onlyOnForms()
                ->creationRules('required', 'string', 'min:6')
                ->updateRules('nullable', 'string', 'min:6', 'sometimes'),

            InlineSelect::make('Status')
                ->size('w-1/3')
                ->options(Setting::userStatuses())
                ->inlineOnIndex()
                ->fillUsing(function ($request, $model) {
                    $model->applyStatus($request->status);
                }),

            BelongsTo::make('Office')
                ->size('w-1/2')
                ->nullable(),
        ];
    }

请注意,这是一个15分钟的工作工具,所以请谨慎使用。