hosnyben / nova-nested-inputs
Nova Nested Fields 是一个 Laravel Nova 字段包,允许用户以嵌套、层次化的结构展示复选框或单选按钮。此包支持无限嵌套层级,为复杂表单需求提供灵活的解决方案。
1.0.0
2024-06-20 02:44 UTC
Requires
- php: ^7.3|^8.0
- laravel/nova: ^4.0
README
Nova Nested Fields 是一个 Laravel Nova 字段包,允许用户以嵌套、层次化的结构展示复选框或单选按钮。此包支持无限嵌套层级,为复杂表单需求提供灵活的解决方案。
要求
php: >=7.3
laravel/nova: ^4.26
演示
嵌套单选按钮输入
嵌套复选框输入
功能
- 复选框/单选按钮字段的无限嵌套。
- 易于与现有的 Laravel Nova 项目集成。
- 可自定义显示和样式选项。
- 支持动态添加和删除嵌套项。
- 直观的用户界面,用于管理嵌套选择。
安装
要安装 Nova Nested Fields 包,请使用 Composer
# Install Nova Nested Inputs
composer require hosnyben/nova-nested-inputs
使用方法
现在您可以使用 NovaNestedInputs 字段与 Nova 一起使用。在 fields
方法中将 NovaNestedInputs 添加为任何其他 Resource
中的字段。
示例
// in a Nova Resource use HosnyBEN\NovaNestedInputs\NovaNestedInputs; public function fields(Request $request) { return [ NovaNestedInputs::make('Category', 'category_id') ->options(function() { return [ ['id' => 1, 'label' => 'Parent 1'], ['id' => 2, 'label' => 'Parent 2'], ['id' => 3, 'label' => 'Parent 3'], [ 'id' => 4, 'label' => 'Parent 4', 'children' => [ ['id' => 5, 'label' => 'Child 4.1'], [ 'id' => 6, 'label' => 'Child 4.2', 'children' => [ ['id' => 8, 'label' => 'Child 4.2.1'], ['id' => 9, 'label' => 'Child 4.2.2'], ], ], ['id' => 7, 'label' => 'Child 4.3'], ], ], ]; }) ->type('radio') ->color('#be860f') ->rules('required'), ] }
设置
"options" 字段结构
[ [ 'id' => 1, // ID of the record 'label' => 'My item', // String : Title of the item 'disabled' => false, // Boolean 'children' => [ // Array of nested item with the exact structure ... ] ], ... ]
许可证
Nova Nested Inputs 是开源软件,许可协议为 MIT 许可证。
作者
由 Hosny BEN 制作