1. Go to this page and download the library: Download ajjitech/searchable-select 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/ */
ajjitech / searchable-select example snippets
namespace App\Livewire;
use App\Models\Country;
use Livewire\Component;
class ContactForm extends Component
{
public $countries;
public $country_id;
public function mount()
{
$this->countries = Country::orderBy('name')->get();
}
public function save()
{
$this->validate([
'country_id' => '
class UserProfile extends Component
{
public $countries;
public $country_id;
public function mount()
{
$this->countries = Country::orderBy('name')->get();
}
}
class UserSkills extends Component
{
public $skills;
public array $selected_skills = [];
public function mount()
{
$this->skills = Skill::orderBy('name')->get();
}
}
class LocationSelector extends Component
{
public $countries;
public $regions = [];
public $cities = [];
public $country_id;
public $region_id;
public $city_id;
public function mount()
{
$this->countries = Country::orderBy('name')->get();
}
public function updatedCountryId($value)
{
$this->regions = Region::where('country_id', $value)->orderBy('name')->get();
$this->region_id = null;
$this->city_id = null;
$this->cities = [];
}
public function updatedRegionId($value)
{
$this->cities = City::where('region_id', $value)->orderBy('name')->get();
$this->city_id = null;
}
}
public $searchTerm = '';
public $countries = [];
public function updatedSearchTerm($value)
{
$this->countries = Country::where('name', 'like', "%{$value}%")
->limit(50)
->get();
}
// Correct
public array $selected_items = [];
// Wrong — null, not an array
public $selected_items;
// If your data uses 'code' instead of 'id'
$countries = [['code' => 'US', 'name' => 'USA']];
public $searchTerm = '';
public $products = [];
public function updatedSearchTerm($value)
{
$this->products = Product::where('name', 'like', "%{$value}%")
->limit(50)
->get();
}
// Good — only id and name
$this->users = User::select('id', 'name')->get();
public function mount()
{
$this->countries = Cache::remember('countries', 3600, fn () =>
Country::orderBy('name')->get()
);
}