moonshine/ layouts-field
用于MoonShine的重复字段组
1.0.2
2024-08-23 07:17 UTC
Requires
- php: ^8.0|^8.1|^8.2
- ext-curl: *
- ext-json: *
Requires (Dev)
- moonshine/moonshine: ^2.20
- orchestra/testbench: ^9.0
- phpunit/phpunit: ^11.0
- rector/rector: ^1.0
Conflicts
- moonshine/moonshine: <2.11
README
MoonShine的布局字段
快速入门
安装
composer require moonshine/layouts-field
用法
MoonShine的字段布局允许您轻松管理重复的字段组。您将能够添加、删除和排序由基本字段组成的组。在布局字段中使用字段有一些限制。您可以使用任何基本字段,除了关系字段。
use MoonShine\Layouts\Fields\Layouts; Layouts::make('Content') ->addLayout('Contact information', 'contacts', [ Text::make('Name'), Email::make('Email'), ]) ->addLayout('Banner section', 'banner', [ Text::make('Title'), Image::make('Banner image', 'thumbnail'), ]),
添加布局
您可以使用以下方法在您的布局字段中添加布局:
addLayout(string $title, string $name, iterable $fields, ?int $limit = null)
$title
参数允许您指定将在表单中显示的字段组名称。$name
参数用于在字段值中存储所选布局。$fields
参数接受一个字段数组,该数组将用于填充表单中的字段组。$limit
允许您设置字段中组数的最大值。
添加类型转换
字段将其值存储为单个JSON字符串。要使用布局字段,您需要为您的模型添加类型转换。
use MoonShine\Layouts\Casts\LayoutsCast; class Article extends Model { protected $casts = [ 'content' => LayoutsCast::class, ]; } Layouts::make('Content', 'content') ->addButton(ActionButton::make('New layout')->icon('heroicons.outline.plus')->primary())
自定义按钮标签
您可以使用ActionButton组件更改默认的“添加布局”按钮文本。
Layouts::make('Content') ->addButton(ActionButton::make('New layout')->icon('heroicons.outline.plus')->primary())
添加搜索字段
您可以在布局列表中添加搜索输入如下:
Layouts::make('Content') ->addLayout('Info section', 'info', [ ... ]) ... ->addLayout('Slider section', 'slider', [ ... ]) ->searchable()