https://github.com/outl1ne/nova-multiselect-filter
Multiselect filter for Laravel Nova.
https://github.com/outl1ne/nova-multiselect-filter
filter laravel laravel-nova laravel-nova-filter
Last synced: about 2 months ago
JSON representation
Multiselect filter for Laravel Nova.
- Host: GitHub
- URL: https://github.com/outl1ne/nova-multiselect-filter
- Owner: outl1ne
- License: mit
- Created: 2020-10-23T13:15:52.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-02-19T21:52:51.000Z (3 months ago)
- Last Synced: 2025-04-13T05:07:22.762Z (about 2 months ago)
- Topics: filter, laravel, laravel-nova, laravel-nova-filter
- Language: Vue
- Homepage:
- Size: 6.73 MB
- Stars: 41
- Watchers: 3
- Forks: 20
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Nova Multiselect Filter
[](https://packagist.org/packages/outl1ne/nova-multiselect-filter)
[](https://packagist.org/packages/outl1ne/nova-multiselect-filter)This [Laravel Nova](https://nova.laravel.com) package adds a multiselect to Nova's filters.
## Requirements
- `php: >=8.0`
- `laravel/nova: ^5.0`## Features
- Multi select
- Single select
- Group select
- Search## Screenshots
### Multiselect

### Groupselect

## Installation
Install the package in a Laravel Nova project via Composer:
```bash
composer require outl1ne/nova-multiselect-filter
```## Usage
The filter can be used when switching `Filter` class with `MultiselectFilter`.
```php
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](https://nova.laravel.com/docs/2.0/resources/fields.html#select-field).
In this example (from Nova docs), all values are grouped by the `group` key:
```php
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')`.
| Option | type | default | description |
| -------------- | --------------- | ---------- | ------------------------------------------------------------------------------------------------------ |
| `options` | Array\|callable | [] | Options in an array as key-value pairs (`['id' => 'value']`). |
| `placeholder` | String | Field name | The placeholder string for the input. |
| `max` | Number | Infinite | The maximum number of options a user can select. |
| `groupSelect` | Boolean | false | For use with option groups - allows the user to select whole groups at once |
| `singleSelect` | Boolean | false | Makes the field act as a single select. The returned value will be an array with one element. |
| `optionsLimit` | Number | 1000 | The maximum number of options displayed at once. Other options are still accessible through searching. |## Localization
The translations file can be published by using the following publish command:
```bash
php artisan vendor:publish --provider="Outl1ne\NovaMultiselectFilter\FieldServiceProvider" --tag="translations"
```You can then edit the strings to your liking.
## Credits
- [Kaspar Rosin](https://github.com/kasparrosin)
- [Tarvo Reinpalu](https://github.com/Tarpsvo)
- [shentao/vue-multiselect](https://github.com/shentao/vue-multiselect)
- [All Contributors](https://github.com/outl1ne/nova-multiselect-filter/graphs/contributors)This package was inspired by [klepak/nova-multiselect-filter](https://github.com/klepak/nova-multiselect-filter)
## License
This project is open-sourced software licensed under the [MIT license](LICENSE.md).