/nova-multiselect-field

A Laravel Nova package that adds a multiselect to Nova's arsenal of fields.

Primary LanguageVueMIT LicenseMIT

Nova Multiselect

This Laravel Nova package adds a multiselect to Nova's arsenal of fields.

Screenshots

Detail View

Form View

Index View

Installation

Install the package in a Laravel Nova project via Composer:

composer require optimistdigital/nova-multiselect-field

Usage

The field is used similarly to Nova's native Select field. The field type in the database should be text-based (ie string, text or varchar), selected values are stored as a stringified JSON array.

use OptimistDigital\MultiselectField\Multiselect;

public function fields(Request $request)
{
    return [
      Multiselect
        ::make('Favourite football teams', 'football_teams')
        ->options([
          'liverpool' => 'Liverpool FC',
          'tottenham' => 'Tottenham Hotspur',
          'bvb' => 'Borussia Dortmund',
          'bayern' => 'FC Bayern Munich',
          'barcelona' => 'FC Barcelona',
          'juventus' => 'Juventus FC',
          'psg' => 'Paris Saint-Germain FC',
        ])

        // Optional:
        ->placeholder('Choose football teams')
        ->max(4)
        ->optionsLimit(5)
    ];
}

Options

Possible options you can pass to the field using the option name as a function, ie ->placeholder('Choose peanuts').

Option type default description
options Array [] 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.
optionsLimit Number 1000 The maximum number of options displayed at once. Other options are still accessible through searching.
resolveForPageResponseUsing Callable null Only for use in conjunction with Page Manager. Allows you to format the value before it is returned through the API.
nullable Boolean false If the field is nullable an empty select will result in null else an empty array ([]) is stored.

Credits

License

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