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
return [
/*
|--------------------------------------------------------------------------
| Default Theme
|--------------------------------------------------------------------------
|
| The default CSS framework to use for rendering components.
| Supported values: 'tailwind', 'bootstrap'
|
*/
'theme' => 'bootstrap', // Change from 'tailwind' to 'bootstrap'
/*
|--------------------------------------------------------------------------
| Bootstrap Version
|--------------------------------------------------------------------------
|
| The Bootstrap version to target for styling.
| Currently supported: '5.3'
|
*/
'bootstrap_version' => '5.3',
];
'theme' => 'tailwind', // or 'bootstrap'
namespace App\Livewire;
use App\Models\Country;
use Livewire\Component;
class ContactForm extends Component
{
public $countries;
public $country_id;
public function mount()
{
// Load all countries
$this->countries = Country::orderBy('name')->get();
}
public function save()
{
$this->validate([
'country_id' => '
// If your model has 'code' and 'country_name' fields
$countries = Country::all(); // [['code' => 'US', 'country_name' => 'United States'], ...]
namespace App\Livewire;
use App\Models\Country;
use Livewire\Component;
class UserProfile extends Component
{
public $countries;
public $country_id;
public function mount()
{
$this->countries = Country::orderBy('name')->get();
}
public function render()
{
return view('livewire.user-profile');
}
}
namespace App\Livewire;
use App\Models\Skill;
use Livewire\Component;
class UserSkills extends Component
{
public $skills;
public $selected_skills = []; // Array to hold multiple selections
public function mount()
{
$this->skills = Skill::orderBy('name')->get();
}
public function render()
{
return view('livewire.user-skills');
}
}
namespace App\Livewire;
use App\Models\{Country, Region, City};
use Livewire\Component;
class LocationSelector extends Component
{
// Options
public $countries;
public $regions = [];
public $cities = [];
// Selected values
public $country_id;
public $region_id;
public $city_id;
public function mount()
{
// Load countries on page load
$this->countries = Country::orderBy('name')->get();
}
public function updatedCountryId($value)
{
// When country changes, load its regions
$this->regions = Region::where('country_id', $value)
->orderBy('name')
->get();
// Reset child selections
$this->region_id = null;
$this->city_id = null;
$this->cities = [];
}
public function updatedRegionId($value)
{
// When region changes, load its cities
$this->cities = City::where('region_id', $value)
->orderBy('name')
->get();
// Reset city selection
$this->city_id = null;
}
public function render()
{
return view('livewire.location-selector');
}
}
// routes/api.php
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::get('/users/search', function (Request $request) {
$query = User::query();
// Search by the query parameter
if ($request->has('search')) {
$search = $request->input('search');
$query->where('name', 'like', "%{$search}%")
->orWhere('email', 'like', "%{$search}%");
}
$users = $query->select('id', 'name')
->limit(50)
->get();
return response()->json([
'data' => $users
]);
});
namespace App\Livewire;
use Livewire\Component;
class AssignTask extends Component
{
public $assigned_user_id;
public function render()
{
return view('livewire.assign-task');
}
}
public $team_members = []; // Array for multiple selections
namespace App\Livewire;
use App\Models\Country;
use Livewire\Component;
class ContactForm extends Component
{
public $countries;
public $country_id;
public $city_id;
protected $rules = [
'country_id' => '
{
$this->countries = Country::all();
}
public function save()
{
$validated = $this->validate();
// Use validated data...
}
public function render()
{
return view('livewire.contact-form');
}
}
public function updated($propertyName)
{
$this->validateOnly($propertyName);
}
public $searchTerm = '';
public $countries = [];
public function updatedSearchTerm($value)
{
$this->countries = Country::where('name', 'like', "%{$value}%")
->limit(50)
->get();
}
// ✅ Correct
$this->country_id = 1;
$this->countries = Country::all(); // Contains id=1
// ❌ Incorrect
$this->country_id = 999; // ID doesn't exist in countries
// If your data uses 'code' instead of 'id'
$countries = [['code' => 'US', 'name' => 'USA']];
'paths' => ['api/*'],
'allowed_origins' => ['*'],
// ✅ Correct
public $selected_items = [];
// ❌ Incorrect
public $selected_items; // null, not an array
// Component
public $country_id; // Property name
protected $rules = [
'country_id' => '