outl1ne / nova-multiselect-filter
Multiselect filter for Laravel Nova.
Installs: 394 289
Dependents: 3
Suggesters: 0
Security: 0
Stars: 40
Watchers: 5
Forks: 16
Open Issues: 5
Language:Vue
Requires
- php: >=8.0
- laravel/nova: ^4.0
- outl1ne/nova-translations-loader: ^5.0.0
README
This Laravel Nova package adds a multiselect to Nova's filters.
Requirements
php: >=7.2
laravel/nova: ^4.0
Features
- Multi select
- Single select
- Group select
- Search
Screenshots
Multiselect
Groupselect
Installation
Install the package in a Laravel Nova project via Composer:
composer require outl1ne/nova-multiselect-filter
Usage
The filter can be used when switching Filter
class with MultiselectFilter
.
use Outl1ne\NovaMultiselectFilter\MultiselectFilter; class BooksByAuthorFilter extends MultiselectFilter { public function apply(Request $request, $query, $value) { return $query->whereHas('books', function ($query) use ($value) { $query->whereIn('author_id', $value); }); } public function options(Request $request) { return Authors::all()->pluck('name', 'id'); } }
Option groups
Option groups are supported. Their syntax is the same as Laravel's option group syntax.
In this example (from Nova docs), all values are grouped by the group
key:
public function options(Request $request) { return [ 'cat' => ['label' => 'Cat', 'group' => 'Pets'], 'dog' => ['label' => 'Dog', 'group' => 'Pets'], 'eagle' => ['label' => 'Eagle', 'group' => 'Birds'], 'parrot' => ['label' => 'Parrot', 'group' => 'Birds'], ] }
Options
Possible options you can pass to the filter using the option name as a function, ie ->placeholder('Choose peanuts')
.
Localization
The translations file can be published by using the following publish command:
php artisan vendor:publish --provider="Outl1ne\NovaMultiselectFilter\FieldServiceProvider" --tag="translations"
You can then edit the strings to your liking.
Credits
This package was inspired by klepak/nova-multiselect-filter
License
This project is open-sourced software licensed under the MIT license.