PHP code example of giacomomasseron / filament-textinput-autocomplete
1. Go to this page and download the library: Download giacomomasseron/filament-textinput-autocomplete 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/ */
giacomomasseron / filament-textinput-autocomplete example snippets
use GiacomoMasseroni\TextInputAutocomplete\Forms\Components\AutocompleteInput;
AutocompleteInput::make('country')
->options([
['value' => 'es', 'label' => 'Spain', 'description' => 'Country'],
['value' => 'fr', 'label' => 'France', 'description' => 'Country'],
])
->searchKeys(['label', 'description'])
->itemView(fn (array $item) => "<strong>{$item['label']}</strong> — {$item['description']}");
use GiacomoMasseroni\TextInputAutocomplete\Forms\Components\AutocompleteInput;
use Illuminate\Support\Facades\Http;
AutocompleteInput::make('repo')
->getSearchResultsUsing(function (string $search) {
$items = Http::get('https://api.github.com/search/repositories', [
'q' => $search,
])->json('items', []);
return collect($items)
->map(fn (array $repo) => [
'value' => $repo['id'],
'label' => $repo['full_name'],
])
->all();
})
->itemView('filament.autocomplete.repo') // a Blade view that receives $item
->minChars(2)
->searchDebounce(300);
bash
php artisan filament:assets