yassi/nova-nested-form
Composer 安装命令:
composer require yassi/nova-nested-form
包简介
A Laravel Nova package that allows you to create/update/delete nested related fields from a parent form.
README 文档
README
Nova Nested Form
This package allows you to include your nested relationships' forms into a parent form.
Installation
composer require yassi/nova-nested-form
Contributions
As I did not anticipate so many people would use that package (which is awesome) and simply do not have enough time to update/enhance this package more regularly on my own, I am looking for other contributors to help me with the maintenance and feature requests. Don't hesitate to contact me if you're interested!
Update to 3.0
The afterFill and beforeFill methods are no longer available.
Attach a new relationship form to a resource
Simply add a NestedForm into your fields. The first parameter must be an existing NovaResource class and the second parameter (optional) must be an existing HasOneOrMany relationship in your model.
namespace App\Nova; use Laravel\Nova\Fields\ID; use Illuminate\Http\Request; use Laravel\Nova\Fields\Text; use Laravel\Nova\Fields\Gravatar; use Laravel\Nova\Fields\Password; // Add use statement here. use Yassi\NestedForm\NestedForm; class User extends Resource { ... public function fields(Request $request) { return [ ID::make()->sortable(), Gravatar::make(), Text::make('Name') ->sortable() ->rules('required', 'max:255'), Text::make('Email') ->sortable() ->rules('required', 'email', 'max:254') ->creationRules('unique:users,email') ->updateRules('unique:users,email,{{resourceId}}'), Password::make('Password') ->onlyOnForms() ->creationRules('required', 'string', 'min:6') ->updateRules('nullable', 'string', 'min:6'), // Add NestedForm here. NestedForm::make('Posts'), ]; }
Choose when to display the form
For instance, if the nested form should only be available if the value of the "has_comments" attirbute is true, you can use:
class Post extends Resource { ... public function fields(Request $request) { return [ Boolean::make('Has Comments'), NestedForm::make('Comments')->displayIf(function ($nestedForm, $request) { return [ [ 'attribute' => 'has_comments', 'is' => true ] ]; ]; } })
The displayIf method is excepted to return an array of array as you may want to add several conditions.
class Post extends Resource { ... public function fields(Request $request) { return [ Boolean::make('Has Comments'), Text::make('Title'), Text::make('Subtitle')->nullable(), Number::make('Number of comments allowed'), NestedForm::make('Comments')->displayIf(function ($nestedForm, $request) { return [ [ 'attribute' => 'has_comments', 'is' => true ], [ 'attribute' => 'title', 'isNotNull' => true ], [ 'attribute' => 'subtitle', 'isNull' => true ], [ 'attribute' => 'title', 'includes' => 'My' ], [ 'attribute' => 'number_of_comments_allowed', 'moreThanOrEqual' => 1 ], // Integration for nova booleanGroup field [ 'attribute' => 'my_multiple_checkbox', 'booleanGroup' => 'the_checkbox_key_to_target' ], ]; }) ]; } }
The package will then add those conditions and dynamically update your form as you fill the fields. The available rules are:
- is
- isNot
- isNull
- isNotNull
- isMoreThan
- isMoreThanOrEqual
- isLessThan
- isLessThanOrEqual
- includes
- booleanGroup
Add a minimum or a maximum number of children
For instance, if you want every user to have at least 3 posts and at most 5 posts, simply use:
NestedForm::make('Posts')->min(3)->max(5),
Please note that the package automatically detects whether the relationship excepts many children or a single child, and sets the maximum value accordingly.
When creating a new user, 3 blank posts will be displayed. If you reach the maximum number of posts, the "Add a new post" button will disappear.
Set the default open/collapse behavior
If you want the nested forms to be opened by default, simply use:
NestedForm::make('Posts')->open(true),
Modify the default heading
You can modify the default heading using the heading() method. You can use the helper method wrapIndex() to add the current child index to your header.
NestedForm::make('Posts')->heading(NestedForm::wrapIndex() . ' // Post'),
You can also add any attribute of the current child into your heading using the helper method wrapAttribute().
NestedForm::make('Posts')->heading(NestedForm::wrapIndex() . ' // ' . NestedForm::wrapAttribute('title', 'My default title')),
Modify the index separator
You can modify the default index separator using the separator() method when you have nested forms (e.g. 1. Post, 1.1. Comment, 1.1.1. Like).
NestedForm::make('Posts')->separator('\'),
yassi/nova-nested-form 适用场景与选型建议
yassi/nova-nested-form 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 507.09k 次下载、GitHub Stars 达 239, 最近一次更新时间为 2018 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「form」 「nova」 「laravel」 「nested」 「relationship」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yassi/nova-nested-form 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yassi/nova-nested-form 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yassi/nova-nested-form 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
A Laravel Nova package for publishable fields
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
A Laravel Nova package for translatable fields
A Laravel Nova Image field. you can paste or drag or chose an image
统计信息
- 总下载量: 507.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 239
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-24