okol/dependent-filter
最新稳定版本:v1.1
Composer 安装命令:
composer require okol/dependent-filter
包简介
Dependent filter component with support for Laravel Nova 5
README 文档
README
Examples
Type
class TypeFilter extends DependentFilter
{
public $component = 'dependent-filter';
public $attribute = 'type';
public $name = 'Type';
public function options(Request $request, array $filters = []): array
{
return collect(TypeEnum::cases())->mapWithKeys(function ($case) {
return [$case->value => $case->name()];
})->toArray();
}
}
Category (Dependent of Type)
class CategoryFilter extends DependentFilter
{
public $component = 'dependent-filter';
public $attribute = 'category_id';
public $dependentOf = ['type'];
public $name = 'Category';
public function options(Request $request, array $filters = []): array
{
if (! empty($filters['type'])) {
return Category::query()
->where('type', $filters['type'])
->whereNull('parent_id')
->pluck('title', 'id')
->toArray();
}
return [];
}
}
SubCategory (Dependent of Category)
class SubCategoryFilter extends DependentFilter
{
public $component = 'dependent-filter';
public $attribute = 'sub_category_id';
public $dependentOf = ['category_id'];
public $name = 'Sub Category';
public function options(Request $request, array $filters = []): array
{
if (! empty($filters['category_id'])) {
return Category::query()
->where('parent_id', $filters['category_id'])
->pluck('title', 'id')
->toArray();
}
return [];
}
}
Usage
public function filters(NovaRequest $request): array
{
return [
new TypeFilter,
new CategoryFilter,
new SubCategoryFilter,
];
}
统计信息
- 总下载量: 715
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-23