PHPackages                             andrechalom/laravel-multiselect - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. andrechalom/laravel-multiselect

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

andrechalom/laravel-multiselect
===============================

A small package for creating html select elements with multiple selections

v0.2.0(4y ago)22.4k2[6 issues](https://github.com/andrechalom/laravel-multiselect/issues)GPL-3.0-or-laterPHPPHP ^8.0

Since Sep 6Pushed 4y ago2 watchersCompare

[ Source](https://github.com/andrechalom/laravel-multiselect)[ Packagist](https://packagist.org/packages/andrechalom/laravel-multiselect)[ Docs](https://github.com/andrechalom/laravel-multiselect)[ RSS](/packages/andrechalom-laravel-multiselect/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)Dependencies (4)Versions (7)Used By (0)

Package Laravel-Multiselect
===========================

[](#package-laravel-multiselect)

[![Latest Version on Packagist](https://camo.githubusercontent.com/be7ae42f75f468810c0a8fec1cfc7318c07b0ba573514256306c75ade8bd6e95/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e6472656368616c6f6d2f6c61726176656c2d6d756c746973656c6563742e737667)](https://packagist.org/packages/andrechalom/laravel-multiselect)[![Software License](https://camo.githubusercontent.com/282a6372b8b8c595e25a8f0bb9a805c64ea331c3c75d8972e9bd8c8a4deb9fbe/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d47504c76332d627269676874677265656e2e737667)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/7c0c591b3de836f6a51a4543a118a33f6e0fda47e620309d1b42fdddaa5c6d2b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e6472656368616c6f6d2f6c61726176656c2d6d756c746973656c6563742e737667)](https://packagist.org/packages/andrechalom/laravel-multiselect)

This package provides a quick interface for adding select boxes from which multiple elements may be selected. The interface is similar to the Laravel Collective [HTML](https://github.com/LaravelCollective/html/) package, and aims to be compatible with it. However, you can use this library without Laravel Collective's HTML.

This package adheres to [PSR 1, 2 and 4](http://www.php-fig.org/psr/).

Requirements
------------

[](#requirements)

- [PHP &gt; 7.0](http://php.net)
- [Laravel &gt; 5.1](https://github.com/laravel/framework) (Tested on 5.4 and 8.8)
- [jQuery &gt; 2.0?](http://jquery.com)

Install
-------

[](#install)

Via Composer

```
$ composer require andrechalom/laravel-multiselect
```

### Service Provider &amp; Facade

[](#service-provider--facade)

Register provider and facade on your config/app.php file. This is necessary for Laravel 5.4, but optional for &gt;= 5.5.

```
'providers' => [
    ...,
    AndreChalom\LaravelMultiselect\MultiselectServiceProvider::class,
]

 'aliases' => [
    ...,
    'Multiselect' => AndreChalom\LaravelMultiselect\MultiselectFacade::class,
 ]
```

### Javascript Configuration

[](#javascript-configuration)

The jQuery code required by this package is in the file multiselect.js. If you use Laravel Mix, you can include it in your mix.js. Otherwise, copy it to your public folder and source it directly in the app layout. Remember to do it after you include jQuery.

Example:

```
mix.js([
    'resources/assets/js/app.js',
    'vendor/andrechalom/laravel-multiselect/resources/assets/js/multiselect.js',
    ], 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');
```

Basic Usage
-----------

[](#basic-usage)

(1) The default behavior creates a select element with an area where the selected options are placed. Use any key =&gt; value array to populate the select.

```
$list = [
    'r' => 'red',
    'g' => 'green',
    'b' => 'blue',
];

{!! Multiselect::select('colors', $list) !!}
```

To provide initial selected options, pass a list of keys as the third argument. All keys in this argument are supposed to be in the options list (but see "Advanced usage" below):

```
{!! Multiselect::select('colors', $list, ['r', 'b']) !!}
```

This can be populated from Eloquent models:

```
{!! Multiselect::select(
    'colors',
    Colors::all()->pluck('name', 'id'),
    isset($person) ? $person->favoriteColors()->pluck('id') : []
) !!}
```

(2) In the Controller, the selected options will be in a array.

```
public function update(Request $request, $id) {
    ...
    $this->validate(['colors' => 'array']);
    $person->favoriteColors()->sync($request->colors);
}
```

(3) style: the span elements generated with Multiselect are of the "multiselector" css class. You can style them as you like, for instance

```
.multiselector { display: inline-block; border: 1px dashed; padding: 2px; margin: 5px; cursor: pointer; }
.multiselector:after { font-family: "Glyphicons Halflings"; content: "\e014"; padding-left: 3px; }
```

A css file is included in this package source code, and includes the above, plus all of the elements that should be styled when using this package.

If would like to change the class or other HTML attributes of the select, option or span elements generated, use the following arguments:

```
{!! Multiselect::select(
    'colors',
    $colors,
    $default_colors,
    ['class' => 'select-class multiselect'],
    [['class' => 'option1-class', 'class' => 'option2-class']],
    ['class' => 'span-class']
) !!}
```

Note that the argument for options excepts an array with the same size of the `$list` parameter. Also note that if you change the select class, you must append "multiselect" or the Javascript code won't work.

Advanced usage
--------------

[](#advanced-usage)

(1) A more advanced usage involves generating the `select` and `span` elements separately. To do so, use the `$selectOnly`argument on the `select` function.

```
{!! Multiselect::select( 'colors', $colors, $default_colors, [], [], [], true) !!}
# ... somewhere else in the page ...
{!! Multiselect::span( 'colors', $colors, $default_colors, [], false) !!}
```

Notice that you must pass the exact same arguments as `$list` and `$selected` for both functions.

(2) When a value passed as default to the `span` function is not found in the `$list` argument, the function generates an element with "Undefined" as label. You can change this behavior to throwing and exception using the last argument of the `span` function (strict mode).

(3) Unlike in LaravelCollective's select, a placeholder option is always generated. You can customize its label using

```
{!! Multiselect::select(
    'colors',
    $colors,
    $default_colors,
    ['placeholder' => 'Pick your favorite colors']
) !!}
```

(4) You can also use an autocomplete input instead of a select element! To do so, import [devbridge's Autocomplete plugin](https://github.com/devbridge/jQuery-Autocomplete), replace the calls to `Multiselect::select()` to `Multiselect::autocomplete()`, and include a `Multiselect::scripts()` call after jQuery is loaded.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ docker build --tag multiselect .
$ docker run -ti multiselect composer fix-style
$ docker run -ti multiselect composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

The idea behind the Multiselect is based on an article by [Michał Wojciechowski](http://odyniec.net/articles/multiple-select-fields/). This library reuses some code from Laravel Collective [HTML](https://github.com/LaravelCollective/html/).

License
-------

[](#license)

This work is licensed under the GNU Public License. Please see [License File](LICENSE) for more information.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~299 days

Recently: every ~372 days

Total

6

Last Release

1714d ago

PHP version history (2 changes)v0.0.1PHP ^5.6|^7.0

v0.2.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/bd5a02200280b6a574441668916a08463cb35f26559a01a7b82e816845c33fa0?d=identicon)[andrechalom](/maintainers/andrechalom)

---

Top Contributors

[![andrechalom](https://avatars.githubusercontent.com/u/1994997?v=4)](https://github.com/andrechalom "andrechalom (34 commits)")

---

Tags

laravelformselectmultiple

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/andrechalom-laravel-multiselect/health.svg)

```
[![Health](https://phpackages.com/badges/andrechalom-laravel-multiselect/health.svg)](https://phpackages.com/packages/andrechalom-laravel-multiselect)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[anahkiasen/former

A powerful form builder

1.3k1.4M14](/packages/anahkiasen-former)[zidbih/laravel-deadlock

Make temporary Laravel workarounds expire and fail CI when ignored.

984.0k](/packages/zidbih-laravel-deadlock)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
