acseo/select-autocomplete-bundle
Symfony bundle to add configurable autocomplete fields to forms with no custom controller. Works with Select2 or any JS, supports Doctrine ORM/ODM out of the box, and lets you customize search properties, display format, identifiers, transformers, URLs, and providers.
Install via Composer:
composer require vendor/package-name
Register the package in config/app.php under providers. For quick testing, leverage the default transformer behavior:
use Vendor\Package\Transformer\DefaultTransformer;
// Basic usage with a model
$transformed = app(DefaultTransformer::class)->transform($model);
// Autocomplete example (now more robust)
$results = app(DefaultTransformer::class)->autocomplete($query, 'search_field');
Disable or customize model transformation via the transformer config:
'transformer' => [
'enabled' => false, // Disable entirely
// OR override specific fields
'fields' => [
'id' => 'custom_id',
'name' => fn($value) => strtoupper($value),
],
],
For dynamic overrides, use the overrideTransformer() method:
$transformer = app(DefaultTransformer::class)
->overrideTransformer(fn($transformer) => $transformer->disable('name'));
Handle collections with unique field IDs (e.g., uniq_id):
$collection = collect([$model1, $model2])
->map(fn($model) => app(DefaultTransformer::class)->transform($model, uniq: 'custom_id'));
Leverage the improved response process for search-as-you-type:
$results = app(DefaultTransformer::class)
->autocomplete($request->input('q'), 'search_field', limit: 5)
->map(fn($item) => [
'value' => $item['id'],
'label' => $item['name'],
]);
display config are properly closed:
'display' => [
'name' => fn($model) => $model->full_name(), // Works in 2.1+
],
Pre-2.1: Callables might throw Closure errors; update to use fn() syntax.uniq in collections, ensure the field exists in all items to avoid UndefinedIndex errors. Defaults to id if omitted.enabled: false in config doesn’t silently fail. Test with:
if (!app(DefaultTransformer::class)->isEnabled()) {
// Fallback logic
}
autocomplete.response:
app()->bind('autocomplete.response', fn($results) => $results->map(...));
afterTransform for post-processing:
$transformer->afterTransform(fn($data) => $data['formatted_at'] = now()->format('Y-m-d'));
How can I help you explore Laravel packages today?