PHP code example of seblhaire / autocompleter
1. Go to this page and download the library: Download seblhaire/autocompleter 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/ */
seblhaire / autocompleter example snippets
'providers' => [
...
Seblhaire\Autocompleter\AutocompleterServiceProvider::class,
...
],
'aliases' => [
...
"AutocompleterHelper" => Seblhaire\Autocompleter\AutocompleterHelper::class
]
sh
$ php artisan vendor:publish
use Seblhaire\Autocompleter\AutocompleterRequest;
...
public function search(AutocompleterRequest $request){
$search = $request->input('search');
$countries = collect(Countries::getList())->filter(function($data) use ($search){ //search in country list
return (mb_stripos($data['code'], $search) !== false) || (mb_stripos($data['country'], $search) !== false);
})->take($request->input('maxresults'));
$res = [];
if (count($countries) > 0){
foreach ($countries as $country){
$res[] = [
config('autocompleter.id_field') => $country['code'],
'country' => $country['country'], // other value available
config('autocompleter.list_field') => Utils::highlite($country['code'] . ' : ' . $country['country'], $request->input('search'), config('autocompleter.highliteclasses'))
];
}
}
return response()->json(['res' => $res]);
}