PHP code example of glebred / search-multiselect-input
1. Go to this page and download the library: Download glebred/search-multiselect-input 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/ */
glebred / search-multiselect-input example snippets
use GlebRed\SearchMultiselectInput\SearchMultiselectInput;
class MyMultiInput extends SearchMultiselectInput
{
//
}
public function updatedQuery()
{
$this->data = User::where('name', 'like', '%' . $this->query . '%')
->get()
->toArray();
}
public function addSelectedItem($user_id)
{
$user = User::findOrFail($user_id, ['id', 'name']);
if (!empty($this->selected_items)) {
if (!in_array($user['id'], array_column($this->selected_items, 'id'))) $this->selected_items[] = $user;
} else {
$this->selected_items[] = $user;
}
//Emit selected items to parent's participantsChanged($participants)
$this->emit('participantsChanged', $this->selected_items);
$this->resetProps();
}
public function removeSelectedItem($id)
{
foreach ($this->selected_items as $key => $item) {
if ($item['id'] == $id) {
unset($this->selected_items[$key]);
break;
}
}
//Emit selected items to parent's participantsChanged($participants)
$this->emit('participantsChanged', $this->selected_items);
}
public function mount($selected_items)
{
$this->selected_items = $selected_items;
}