The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

Nova Multiselect Filter

outl1ne/nova-multiselect-filter image

Nova Multiselect Filter stats

Downloads
137.9K
Stars
33
Open Issues
5
Forks
16

View on GitHub →

Multiselect filter for Laravel Nova.

Nova Multiselect Filter

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').

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:

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.

outl1ne photo

Digital product agency based in Tallinn, Estonia.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Outl1Ne Nova Multiselect Filter Related Articles

PHP 7.3’s First Release Candidate is Here image

PHP 7.3’s First Release Candidate is Here

Read article
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
LoadForge logo

LoadForge

Scalable load testing for web apps & APIs. Simulate real-world traffic and identify breaking points and performance limits with powerful, scalable load tests designed for Laravel.

LoadForge
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel
Blastup logo

Blastup

Blastup provides social media enhancement services including buying Instagram likes, followers, and views, with features like instant delivery and a variety of packages to suit different needs.

Blastup