1. Go to this page and download the library: Download etdte/livewire-multiselect library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
etdte / livewire-multiselect example snippets
class Index extends Component
{
use LivewireMultiselect\HasSelect;
protected $listeners = ['select'];
// for selected options - multiple
public ?array $teamFilter = null;
// for selected option - single
public int|string|null $teamFilter = null;
// available options
public ?Collection $teams = null;
public function selected(string $name, array $value)
{
if ($name === 'teamFilter') {
// do something
}
}
public function selected(string $name, int|string|null $value)
// reset component variables
$this->reset('teamFilter');
$this->anotherFilter = [2,3];
// reset options on all component selects
$this->emitTo('multiselect', 'refresh', $this);
// you can also do something like this,
// BUT ALL NOT PASSED SELECTS, WITHIN THE COMPONENT, WILL BE RESET TO EMPTY.
$this->emitTo('multiselect', 'refresh', ['id' => $this->id, 'teamFilter' => [2]]);