harrald / nova-combobox-filter
A Laravel Nova combobox filter. Supports selecting multiple items
Installs: 88 170
Dependents: 0
Suggesters: 0
Security: 0
Stars: 13
Watchers: 1
Forks: 2
Open Issues: 1
Language:Vue
pkg:composer/harrald/nova-combobox-filter
Requires
- php: ^7.3|^8.0
- laravel/nova: ^4.0|^5.0
README
This component is based on the Headless UI Combobox component and adds a multiselect filter to Laravel Nova.
Requirements
php: >=7.3laravel/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
$nameis the displayable name of the filter. - The method
columnNamemust return the name of the column to filter on - The
optionsmethod should return aIlluminate\Support\Collectionwith 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
Credits
This package was inspired by optimistdigital/nova-multiselect-filter
License
This project is open-sourced software licensed under the MIT license.

