定制 harrald/nova-combobox-filter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

harrald/nova-combobox-filter

最新稳定版本:1.2.0

Composer 安装命令:

composer require harrald/nova-combobox-filter

包简介

A Laravel Nova combobox filter. Supports selecting multiple items

README 文档

README

Latest Version on Packagist Total Downloads Total Downloads Total Downloads

This component is based on the Headless UI Combobox component and adds a multiselect filter to Laravel Nova.

Requirements

  • php: >=7.3
  • laravel/nova: ^4.0

Installation

Install via Composer:

composer require harrald/nova-combobox-filter

Usage

The nova-combobox-filter extends the Nova select filter. And thus follows the same logic as to how to implement it.

Filter

Make a new Filter class in App/Nova/Filters and let it extend the \Harrald\NovaComboboxFilter\NovaComboboxFilter class.

Use the following format:

<?php

namespace App\Nova\Filters;

use Harrald\NovaComboboxFilter\NovaComboboxFilter;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;

class OpenPaidStateFilter extends NovaComboboxFilter
{
    /**
     * The displayable name of the filter.
     *
     * @var string
     */
    public $name = 'State';

    /**
     * The name of the column to filter on
     */
    protected function columnName(): string
    {
        return 'state';
    }

    /**
     * Get the filter's available options.
     */
    public function options(Request $request): Collection
    {
        return Collection::make([
            'Open' => 'open',
            'Paid' => 'paid',
        ]);
    }
}
  • The property $name is the displayable name of the filter.
  • The method columnName must return the name of the column to filter on
  • The options method should return a Illuminate\Support\Collection with key/value pairs.

With Dynamic options

public function options(Request $request): Collection
{
    return User::all()->pluck('id', 'name');
}

Resource

Use the new filter in you Resource. Follows the same logic as a any other Nova filter

/**
 * Get the filters available for the resource.
 *
 * @param NovaRequest $request
 * @return array
 */
public function filters(NovaRequest $request): array
{
    return [
        OpenPaidStateFilter::make(),
    ];
}

Screenshots

multi options selected

filter options by typing

Credits

This package was inspired by optimistdigital/nova-multiselect-filter

License

This project is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 94.63k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 1
  • Forks: 2
  • 开发语言: Vue

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-11