lupennat/nova-expandable-many
Composer 安装命令:
composer require lupennat/nova-expandable-many
包简介
Laravel Nova - Expandable Many
README 文档
README
Requirements
php: ^7.4 | ^8laravel/nova: ^4
Installation
composer require lupennat/nova-expandable-many:^3.0
| NOVA | PACKAGE |
|---|---|
| <4.29.5 | 1.x |
| <4.32.6 | 2.x |
| >=4.32.6 | 3.x |
Usage
Register Trait HasExpandableMany globally on Resources.
the Trait include an override of
indexFieldsmethod, it call methodwithoutListableFieldsNotExpandableinstead ofwithoutListableFieldson FieldCollection; if you already register a custom ovveride ofindexFieldsyou can do it manually without using provided trait.
ExpandableMany Package automatically enable a new method expandable for all Many Relationship Fields:
- BelongsToMany
- HasMany
- HasManyThrough
- MorphedByMany
- MorphMany
- MorphToMany
The relation table (without any custom actions and lenses) will be displayed as a collapsable row on the index page.
use Laravel\Nova\Fields\HasMany; use Laravel\Nova\Http\Requests\NovaRequest; class User extends Resource { use Lupennat\ExpandableMany\HasExpandableMany; public function fields(Request $request) { return [ HasMany::make('User Post', 'posts', Post::class)->expandable(); ]; } }
By Default expandable use Show and Hide as labels, you can change labels using meta
HasMany::make('User Post', 'posts', Post::class)->expandable() ->withMeta([ 'expandableShowLabel' => 'Custom Show', 'expandableHideLabel' => 'Custom Hide', ])
you can also define a custom HTML using
HasMany::make('User Post', 'posts', Post::class)->expandable() ->withMeta([ 'expandableShowHtml' => '<strong>Custom Show Html</strong>', 'expandableHideHtml' => '<strong>Custom Hide Html</strong>', ])
if both custom label and HTML are defined, HTML will be used
By Default expandable do not store on browser history any status, you can change it using meta
HasMany::make('User Post', 'posts', Post::class)->expandable() ->withMeta([ // 'expandableStoreStatus' => 'full', // will store status also for relationships 'expandableStoreStatus' => 'accordion', // will store status only for accordion 'expandableStoreStatus' => '', // will not store any status ])
Expandable can be skipped and an empty field is shown (by Default is false)
HasMany::make('User Post', 'posts', Post::class)->expandable() ->withMeta([ 'expandableSkip' => true, 'expandableSkipLabel' => '', // default is '—' ])
Expandable can disable standard actions (By Default is enabled)
HasMany::make('User Post', 'posts', Post::class)->expandable() ->withMeta([ 'expandableUseStandardActions' => false, // disable create/edit/view/delete/restore ])
Display Callback
Expandable Many will resolve a display callback foreach resource, you can use it to manipulate meta attributes dinamically.
HasMany::make('User Post', 'posts', Post::class) ->expandable(function(HasMany $field, $resource) { $resource->loadCount('posts'); $field->withMeta([ 'expandableShowLabel' => 'Show ' . $resource->posts_count, 'expandableSkip' => $resource->posts_count === 0 ]); })
By Default Expandable do not resolve relations, accessing a relationAttribute through the
$resourcewill execute a query against database to load all related models.
Lens
If you want to use Expandable Many inside a Lens, you need to register also the trait HasExpandableManyLens inside your Lens.
use Laravel\Nova\Fields\HasMany; use Laravel\Nova\Http\Requests\NovaRequest; use Laravel\Nova\Lenses\Lens; class UserLens extends Lens { use Lupennat\ExpandableMany\HasExpandableManyLens; public function fields(Request $request) { return [ HasMany::make('User Post', 'posts', Post::class)->expandable(); ]; } }
Credits
This package is based on the original idea from Nova Expandable Row
lupennat/nova-expandable-many 适用场景与选型建议
lupennat/nova-expandable-many 是一款 基于 Vue 开发的 Composer 扩展包,目前已累计 42.2k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2023 年 12 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「nova」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lupennat/nova-expandable-many 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lupennat/nova-expandable-many 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lupennat/nova-expandable-many 相关的其它包
同方向 / 同关键字的高下载量 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
A Laravel Nova Image field. you can paste or drag or chose an image
A Laravel Nova Mail testing tool.
统计信息
- 总下载量: 42.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-05
