moonshine/layouts-field
Composer 安装命令:
composer require moonshine/layouts-field
包简介
Field for repeating groups of fields for MoonShine
README 文档
README
Layouts field for MoonShine
Requirements
- MoonShine v4.0+
Support MoonShine versions
| MoonShine | Layouts |
|---|---|
| 2.0+ | 1.0+ |
| 3.0+ | 2.0+ |
| 4.0+ | 3.0+ |
Quick start
Install
composer require moonshine/layouts-field
Usage
Field Layouts for MoonShine allows you to easily manage repeating groups of fields. You will be able to add, delete and sort groups consisting of basic fields. There are some restrictions on the use of fields in the Layouts field. You can use any basic fields except Relationships fields.
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'), ], validation: ['title' => 'required']),
Adding layouts
Layouts can be added using the following method on your Layouts fields:
addLayout( string $title, string $name, iterable $fields, ?int $limit = null, iterable $headingAdditionalFields = null, array $validation = [] )
$title- allows you to specify the name of a group of fields that will be displayed in the form,$name- used to store the chosen layout in the field's value,$fields- accepts an array of fields that will be used to populate a group of fields in the form,$limit- allows you to set the max number of groups in the field,$headingAdditionalFields- components in header,$validation- validation rules.
Adding cast
The field stores its values as a single JSON string. To use the Layouts field, you need to add a cast for your model.
use MoonShine\Layouts\Casts\LayoutsCast; class Article extends Model { protected function casts(): array { return [ 'content' => LayoutsCast::class, ]; } }
Customizing the button label
You can change the default "Add layout" button's text using the ActionButton component:
Layouts::make('Content') ->addButton(ActionButton::make('New layout')->icon('plus')->primary())
Adding search field
You can add search input in layout list as follows:
Layouts::make('Content') ->addLayout('Info section', 'info', [ // ... ]) // ... ->addLayout('Slider section', 'slider', [ // ... ]) ->searchable()
Validation
Layouts::make('Content') ->addLayout( 'Info section', 'info', [ Email::make('Email') ], validation: ['email' => ['required', 'email']], attributes: ['email' => 'E-mail'] )
Layouts::make('Content') ->addLayout('Info section', 'info', [ Email::make('Email') ]), ->addLayout('Additionally section', 'additionally', [ Text::make('Title') ]) ->validation([ 'info' => ['email' => 'required'], 'additionally' => ['title' => 'required']] )
Layouts::make('Content') ->addLayout('Info section', 'info', [ Email::make('Email') ], validation: ['email' => ['email']], attributes: ['email' => 'E-mail']), ->addLayout('Additionally section', 'additionally', [ Text::make('Title') ]) ->validation( [ 'info' => ['email' => ['required']], 'additionally' => ['title' => 'required'] ], attributes: ['additionally' => ['title' => 'Заголовок']] )
moonshine/layouts-field 适用场景与选型建议
moonshine/layouts-field 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.63k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2024 年 04 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「Flexible」 「moonshine」 「fields-group」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 moonshine/layouts-field 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 moonshine/layouts-field 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 moonshine/layouts-field 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Edit your .env file in Laravel directly from the command line.
Kinikit - PHP Application development framework MVC component
User permissions for MoonShine
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
Task scheduling extension for MoonShine
统计信息
- 总下载量: 8.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-12