ziffmedia/nova-select-plus
Composer 安装命令:
composer require ziffmedia/nova-select-plus
包简介
A Nova select field for simple and complex select inputs
关键字:
README 文档
README
Installation
composer require ziffmedia/nova-select-plus
Versions & Compatibility
- Version
^1.0supports Nova 2-3 - Version
^2.0supports Nova 4 (with Vue 3, dark mode support, etc) - Version
^2.1supports Nova 5
Description & Use Cases
This Nova component was built to satisfy the use cases just beyond Nova's built-in <select> component. Here are
some scenarios where you might want SelectPlus (which uses vue-select) over the simple Select:
Select For BelongsToMany and MorphsToMany On the Form Screen
The default Nova experience for BelongsToMany and MorphsToMany is to have a separate UI screen for
attaching/detaching and syncing relationships through a "Pivot" model. For simple relationships (relationships that do
not have addition pivot values or the only value in the pivot table is there for ordering), it is benefitial to move
this Selection to the Form workflow instead of a separate workflow.
Ajax For Options
For Select's that have between a handful to several 1000 options, it is more peformant to load the full list of options only on the screen that needs it: the Form screen.
There are 2 options for Ajax Options, the default is to load them all on the Form load. The second is to allow for full option searching (in this case you can write you own ajax search resolver).
Reordering Simple Pivot/BelongsToMany Relations
Through ->reorderable(), you can enable a SelectPlus field to be reorderable. This allows, at BelongsToMany->sync()
time, to populate a pivot value useful for ordering relations.
Usage
use ZiffMedia\NovaSelectPlus\SelectPlus;
// setup model like normal: public function statesLivedIn() { return $this->belongsToMany(State::class, 'state_user_lived_in')->withTimestamps(); } // add Nova Resource Field SelectPlus::make('States Lived In', 'statesLivedIn', State::class),
Options & Examples
->label(string|closure $attribute) Pick a different attribute to use as the label
Default: 'name'
SelectPlus::make('States Lived In', 'statesLivedIn', State::class) ->label('code')
If a closure is provided, it will be called and the value can be utilized. Additionally, the output may be HTML as the component will v-html the output on the frontend:
// Using php 7.4 short functions: SelectPlus::make('States Visited', 'statesVisited', State::class) ->label(fn ($state) => $state->name . " <span class=\"text-xs\">({$state->code})</span>")
->usingIndexLabel() & ->usingDetailLabel()
Default is to produce a count of the number of items on the index and detail screen
If a string name is provided, the name attribute is plucked and comma joined:
SelectPlus::make('States Lived In', 'statesLivedIn', State::class) ->usingIndexLabel('name'),
If a closure is provided, it will be called, and the value will be utilized. If the value is a string, it will be placed:
SelectPlus::make('States Lived In', 'statesLivedIn', State::class) ->usingIndexLabel(fn($models) => $models->first()->name ?? ''),
If an array is returned, the Index and Detail screens will produce a <ol> or <ul> list:
SelectPlus::make('States Lived In', 'statesLivedIn', State::class) ->usingIndexLabel(fn($models) => $models->pluck('name')),
->reorderable(string $pivotOrderAttribute) - Ability to reorder multiple selects
// assuming in the User model: public function statesVisited() { return $this->belongsToMany(State::class, 'state_user_visited') ->withPivot('order') ->orderBy('order') ->withTimestamps(); } // inside the Nova resource: SelectPlus::make('States Lived In', 'statesLivedIn', State::class) ->reorderable('order'),
->optionsQuery(closure) - Ability to apply changes to options query object
// inside the Nova resource (exclude all states that start with C) SelectPlus::make('States Lived In', 'statesLivedIn', State::class) ->optionsQuery(function (Builder $query) { $query->where('name', 'NOT LIKE', 'C%'); })
- Note: this will apply before any
ajaxSearchable()functionality, it will not replace it but be applied along withajaxSearchable()if it exists
->ajaxSearchable(string|closure|true) Ajax search for values
Given a string, models will be search the resources via the provided attribute using WHERE LIKE. Given a callback, returning a Collection will populate the dropdown:
SelectPlus::make('States Visited', 'statesVisited', State::class) ->ajaxSearchable(function ($search) { return StateModel::where('name', 'LIKE', "%{$search}%")->limit(5); })
ziffmedia/nova-select-plus 适用场景与选型建议
ziffmedia/nova-select-plus 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 608.65k 次下载、GitHub Stars 达 96, 最近一次更新时间为 2020 年 02 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ajax」 「nova」 「laravel」 「select」 「vue-select」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ziffmedia/nova-select-plus 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ziffmedia/nova-select-plus 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ziffmedia/nova-select-plus 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
A Laravel Nova package for publishable fields
A Laravel Nova package for translatable fields
Selenium4 (WebDriver) driver for Mink framework
laravel middleware to allow ajax only calls
统计信息
- 总下载量: 608.65k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 96
- 点击次数: 25
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-29






