zakariatlilani / nova-nested-tree
Nova vue-tree-select 字段用于管理嵌套分类关系。
0.0.3
2024-05-01 21:56 UTC
Requires
- php: ^8.0
- kalnoy/nestedset: ^6.0
README
支持 Laravel nova 4。对于 nova 3,请使用 此包。
支持
多对多字段用于简单管理嵌套关系树。使关联关系易于附加。
路线图
- 验证
- 在详情中显示所选分类
- 传递自己的树的能力
- 当树中有许多记录(例如 10k+)时,具有
延迟加载
数据的能力。
安装
composer require zakariatlilani/nova-nested-tree
用法
此字段使用由 kalnoy/nestedset 包提供的树
此字段底层使用 riophae/vue-treeselect
use zakariatlilani\NovaNestedTree\NestedTreeAttachManyField;
public function fields(Request $request) { return [ NestedTreeAttachManyField::make('Offer Categories',"categories","App\Nova\Category"), ]; }
您的模型应该具有 kalnoy/nestedset 包的 NodeTrait 特性,请参阅路线图
class Category extends Model { use NodeTrait; }
选项
以下是几个自定义选项
->searchable(bool $searchable)
->withIdKey(string $idKey = 'id')
// - 嵌套模型中的 id 列表名->withLabelKey(string $labelKey = 'name')
// - 标签列名在嵌套模型中->withActiveKey(string $activeKey)
// - active_status 列名在嵌套模型中,用于禁用选项->withChildrenKey(string $childrenKey)
// - 嵌套模型中的子键->withPlaceholder(string $placeholder)
// - 树选择中的占位符->withMaxHeight(int $maxHeight)
->withSortValueBy(string $sortBy)
// - @see https://vue-treeselect.js.org/#flat-mode-and-sort-values->withAlwaysOpen(bool $alwaysOpen)
// - 默认情况下选择是打开的,但您可以更改其行为->withFlatten(bool $flatten)
// - 默认启用扁平化,但您可以更改其行为->useSingleSelect()
// - 选择单个值的能力->useAsField()
// - 将结果写入字段而不使用关系的能力
使用 whitecube/nova-flexible-content 包的示例
use Whitecube\NovaFlexibleContent\Flexible; use zakariatlilani\NovaNestedTree\NestedTreeAttachManyField; /** * Get the fields displayed by the resource. * * @param \Illuminate\Http\Request $request * @return array */ public function fields(Request $request) { return [ // ... Flexible::make('Content') ->addLayout('Simple content section', 'tree_section', [ NestedTreeAttachManyField::make('Tree',"tree","App\Nova\Category") ->useAsField(), ]) ]; }
授权
此字段也尊重策略:即角色/权限
- RolePolicy: attachAnyPermission($user, $role)
- RolePolicy: attachPermission($user, $role, $permission)
- PermissionPolicy: viewAny($user)
验证
您可以设置最小值、最大值、大小、必填项或自定义规则对象
->rules('min:5', 'max:10', 'size:10', 'required', new CustomRule)`
贡献
请随意提出更改建议,要求新功能或自行修复错误。
希望此包对您有所帮助。