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

Filament Searchable Input Laravel Package

defstudio/filament-searchable-input

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require defstudio/filament-searchable-input
    

    Publish the config (if needed):

    php artisan vendor:publish --provider="Defstudio\FilamentSearchableInput\FilamentSearchableInputServiceProvider" --tag="filament-searchable-input-config"
    
  2. First Use Case Replace a standard Select or TextInput in a Filament form/resource with a searchable autocomplete:

    use Defstudio\FilamentSearchableInput\Forms\Components\SearchableInput;
    
    SearchableInput::make('user_id')
        ->label('User')
        ->searchableOptions(function () {
            return User::query()->limit(10)->get();
        })
        ->searchableOptionLabel('name')
        ->searchableOptionValue('id')
        ->required(),
    
  3. Where to Look First

    • Package Docs (if available)
    • config/filament-searchable-input.php (for global defaults)
    • vendor/defstudio/filament-searchable-input/src (for advanced customization)

Implementation Patterns

Core Workflows

  1. Basic Searchable Input

    SearchableInput::make('category_id')
        ->searchableOptions(Category::query()->where('active', true))
        ->searchableOptionLabel('name')
        ->searchableOptionValue('id')
        ->placeholder('Search categories...');
    
  2. Dynamic Query Building Use closures for real-time filtering:

    ->searchableOptions(function (string $query) {
        return Product::query()
            ->where('name', 'like', "%{$query}%")
            ->orWhere('sku', 'like', "%{$query}%")
            ->limit(20)
            ->get();
    })
    
  3. Integration with Filament Forms/Resources Replace Select or TextInput in:

    • Form Builder:
      $form->components([
          SearchableInput::make('related_post_id')
              ->relationship('posts', 'title')
              ->required(),
      ]);
      
    • Table Columns (for inline editing):
      use Defstudio\FilamentSearchableInput\Tables\Columns\SearchableInputColumn;
      
      SearchableInputColumn::make('author_id')
          ->label('Author')
          ->searchableOptions(User::query())
          ->searchableOptionLabel('name')
          ->searchableOptionValue('id');
      
  4. Debouncing Search Requests Configure in config/filament-searchable-input.php:

    'debounce' => 300, // ms
    
  5. Customizing the UI Extend the default Blade view (resources/views/vendor/filament-searchable-input/input.blade.php) or override via:

    ->view('custom.path.to.view')
    

Advanced Patterns

  1. Remote Data Fetching Fetch options from an API:

    ->searchableOptions(function (string $query) {
        return Http::get("https://api.example.com/search?q={$query}")->json()['data'];
    })
    ->searchableOptionLabel('display_name')
    ->searchableOptionValue('id');
    
  2. Caching Search Results Cache query results to reduce DB load:

    ->searchableOptions(function (string $query) {
        return Cache::remember("searchable_{$query}", now()->addMinutes(5), function () use ($query) {
            return Product::where('name', 'like', "%{$query}%")->limit(10)->get();
        });
    })
    
  3. Multi-Select Support Combine with Select for multi-value selection:

    SearchableInput::make('tags')
        ->searchableOptions(Tag::query())
        ->searchableOptionLabel('name')
        ->searchableOptionValue('id')
        ->multiple()
        ->maxItems(5);
    
  4. Integration with Filament Spatie Media Library Search media files:

    ->searchableOptions(function (string $query) {
        return Media::query()
            ->where('title', 'like', "%{$query}%")
            ->orWhere('description', 'like', "%{$query}%")
            ->limit(10)
            ->get();
    })
    ->searchableOptionLabel('title')
    ->searchableOptionValue('id');
    

Gotchas and Tips

Common Pitfalls

  1. Performance Issues

    • Problem: Slow queries with large datasets.
    • Fix: Add limit() and select() to queries:
      ->searchableOptions(function (string $query) {
          return User::query()
              ->where('name', 'like', "%{$query}%")
              ->select('id', 'name') // Only fetch needed columns
              ->limit(20)
              ->get();
      })
      
    • Tip: Use database indexes on searchable columns.
  2. Case Sensitivity

    • Problem: Searches may be case-sensitive.
    • Fix: Use ->whereRaw('LOWER(name) LIKE LOWER(?)', ["%{$query}%"]) or add a full-text index.
  3. CORS Errors (API Endpoints)

    • Problem: If fetching remote data, CORS may block requests.
    • Fix: Ensure your API includes proper CORS headers or proxy requests via a Laravel route.
  4. Stale Cache

    • Problem: Cached search results become outdated.
    • Fix: Invalidate cache when relevant data changes (e.g., Product::updated() event).
  5. JavaScript Conflicts

    • Problem: Conflicts with other Filament plugins or custom JS.
    • Fix: Check browser console for errors. Override the default JS via:
      ->extraAttributes(['data-custom-attr' => 'value'])
      ->script('
          document.addEventListener("DOMContentLoaded", function() {
              console.log("Custom JS for searchable input");
          });
      ')
      

Debugging Tips

  1. Log Queries Enable Laravel query logging in AppServiceProvider:

    public function boot()
    {
        if (app()->environment('local')) {
            DB::enableQueryLog();
        }
    }
    

    Then inspect logs after triggering the search.

  2. Inspect Network Requests Use browser DevTools (Network tab) to verify:

    • API endpoints are hit.
    • Payloads match expectations.
    • Responses are parsed correctly.
  3. Disable Debounce Temporarily Override debounce in config for testing:

    'debounce' => 0, // Immediate search
    

Extension Points

  1. Custom Option Rendering Override how options are displayed in the dropdown:

    ->searchableOptionView('custom.view.path')
    ->searchableOptionViewData(function ($option) {
        return ['extra_data' => $option->extra_field];
    })
    
  2. Predefined Values Add static options alongside dynamic ones:

    ->options([
        'all' => 'All Categories',
        'featured' => 'Featured',
    ])
    ->searchableOptions(Category::query())
    
  3. Custom Styling Use Filament’s CSS variables or add custom classes:

    ->extraAttributes(['class' => 'custom-searchable-input'])
    
  4. Event Listeners Listen to search events (e.g., searchable-input:searching):

    event(new SearchableInputSearching($query, $component));
    

    Register listeners in EventServiceProvider.

  5. Localization Override labels/placeholders:

    ->placeholder(__('filament-searchable-input::search.placeholder'))
    ->label(__('filament-searchable-input::search.label'))
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky