PHP code example of rishadblack / wire-tomselect

1. Go to this page and download the library: Download rishadblack/wire-tomselect 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/ */

    

rishadblack / wire-tomselect example snippets


namespace App\Http\Livewire;

use Rishadblack\WireTomselect\SearchComponent;
use App\Models\User;

class UserSearch extends SearchComponent
{
    public function builder(): Builder
    {
        return User::query(); // Base query for fetching data
    }

    public function configure(): void
    {
        $this->isSearchable();
        $this->setSearchField(['name', 'email']); // Fields to search in
    }
}

$this->setValueField('id');
$this->setLabelField('name');

$this->setSearchField(['name', 'email']);

$this->setMaxOptions(10);

namespace App\Http\Livewire;

use Rishadblack\WireTomselect\SearchComponent;
use App\Models\Product;

class ProductSearch extends SearchComponent
{
    public function builder(): Builder
    {
        return Product::query();
    }

    public function configure(): void
    {
        $this->isSearchable();
        $this->setSearchField(['name', 'sku']);
        $this->setMaxOptions(15);
    }
}
bash
php artisan vendor:publish --tag=wire-tomselect-views