Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Select Autocomplete Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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');

Implementation Patterns

Transformer Overrides

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'));

Collection Context

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'));

Autocomplete Workflow

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'],
    ]);

Gotchas and Tips

Callable Fixes

  • Display Options: Ensure callables in 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.

Collection Quirks

  • Uniq Field ID: If using uniq in collections, ensure the field exists in all items to avoid UndefinedIndex errors. Defaults to id if omitted.

Transformer Debugging

  • Disabled State: Verify enabled: false in config doesn’t silently fail. Test with:
    if (!app(DefaultTransformer::class)->isEnabled()) {
        // Fallback logic
    }
    

Extension Points

  • Autocomplete Pipeline: Extend the response process by binding a listener to autocomplete.response:
    app()->bind('autocomplete.response', fn($results) => $results->map(...));
    
  • Field Overrides: Use afterTransform for post-processing:
    $transformer->afterTransform(fn($data) => $data['formatted_at'] = now()->format('Y-m-d'));
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui