PHP code example of bangsystems / livewire-select
1. Go to this page and download the library: Download bangsystems/livewire-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/ */
bangsystems / livewire-select example snippets
public function options($searchTerm = null) : Collection
{
//
}
public function options($searchTerm = null) : Collection
{
return collect([
[
'value' => 'honda',
'description' => 'Honda',
],
[
'value' => 'mazda',
'description' => 'Mazda',
],
[
'value' => 'tesla',
'description' => 'Tesla',
],
]);
}
// In CarModelSelect component
public function options($searchTerm = null) : Collection
{
$modelsByBrand = [
'tesla' => [
['value' => 'Model S', 'description' => 'Model S'],
['value' => 'Model 3', 'description' => 'Model 3'],
['value' => 'Model X', 'description' => 'Model X'],
],
'honda' => [
['value' => 'CRV', 'description' => 'CRV'],
['value' => 'Pilot', 'description' => 'Pilot'],
],
'mazda' => [
['value' => 'CX-3', 'description' => 'CX-3'],
['value' => 'CX-5', 'description' => 'CX-5'],
['value' => 'CX-9', 'description' => 'CX-9'],
],
];
$carBrandId = $this->getDependingValue('car_brand_id');
if ($this->hasDependency('car_brand_id') && $carBrandId != null) {
return collect(data_get($modelsByBrand, $carBrandId, []));
}
return collect([
['value' => 'Model S', 'description' => 'Tesla - Model S'],
['value' => 'Model 3', 'description' => 'Tesla - Model 3'],
['value' => 'Model X', 'description' => 'Tesla - Model X'],
['value' => 'CRV', 'description' => 'Honda - CRV'],
['value' => 'Pilot', 'description' => 'Honda - Pilot'],
['value' => 'CX-3', 'description' => 'Mazda - CX-3'],
['value' => 'CX-5', 'description' => 'Mazda - CX-5'],
['value' => 'CX-9', 'description' => 'Mazda - CX-9'],
]);
}
bash
php artisan make:livewire CarModelSelect