Installation:
composer require novadaemon/filament-combobox
Ensure compatibility with your Filament version (3.x or 4.x).
First Use Case:
Replace a standard Select field with Combobox in a Filament form:
use Novadaemon\FilamentCombobox\Combobox;
Combobox::make('field_name')
->options(['key1' => 'Label 1', 'key2' => 'Label 2'])
Where to Look First:
Select field methods (since Combobox extends it).Static Options: Use for fixed, non-database-backed choices (e.g., status flags, predefined tags):
Combobox::make('status')
->options([
'active' => 'Active',
'inactive' => 'Inactive',
])
->required()
->default('active');
Eloquent Relationships:
Fetch data dynamically from a model relationship (e.g., User::hasMany('Roles')):
Combobox::make('roles')
->relationship('roles', 'name') // 'roles' = relationship, 'name' = display column
->searchable() // Enable search/filtering
->preload(); // Preload related data for performance
Query Modifiers: Customize the underlying query (e.g., filter active categories):
Combobox::make('categories')
->relationship('categories', 'title')
->query(fn (Builder $query) => $query->where('is_active', true));
Multi-Select: Enable multiple selections (default behavior):
Combobox::make('tags')
->options(['tag1' => 'Tag 1', 'tag2' => 'Tag 2'])
->multiple(); // Explicitly declare (redundant but clear)
Integration with Filament Tables: Use in table columns for inline editing:
Table::make(...)
->columns([
Tables\Columns\SelectColumn::make('status')
->options(['active' => 'Active', 'inactive' => 'Inactive'])
->combobox(), // Convert to combobox
]);
Conditional Logic:
Combine with Filament’s visible()/required():
Combobox::make('advanced_option')
->options(['opt1' => 'Option 1'])
->visible(fn (?User $record) => $record?->is_admin);
Custom Styling: Override Blade templates or use CSS:
Combobox::make('custom_styled')
->options(['opt1' => 'Option 1'])
->extraAttributes(['class' => 'bg-gray-100']);
API Integration:
Fetch options from an external API (use ->options() with a closure):
Combobox::make('api_data')
->options(fn () => Http::get('https://api.example.com/data')->json());
Relationship Caching:
->relationship() may not update if the related model changes.->preload() or manually refresh the query:
->query(fn (Builder $query) => $query->fresh())
Search Performance:
->limit(10) or use database indexes.Default Values:
->default('nonexistent')) may break.->options() or use ->default(null).Multi-Select Quirks:
->multiple() may not persist if the model lacks a pivot table.belongsToMany or morphToMany.Filament 4.x Breaking Changes:
->searchable()) may behave differently in Filament 4.Inspect Options: Dump the rendered options to debug:
->options(fn () => collect(['opt1' => 'Option 1'])->dump()->all())
Check JavaScript Errors:
Open browser dev tools (F12) to verify if the combobox’s JS is loading.
Log Queries: Enable Laravel query logging to debug relationship issues:
DB::enableQueryLog();
// ... use combobox ...
dd(DB::getQueryLog());
Custom Templates:
Override the Blade view (resources/views/vendor/filament-combobox/...) for UI changes.
Add-on Methods: Extend the class to add custom logic:
class CustomCombobox extends Combobox {
public function customMethod() { ... }
}
Event Listeners:
Hook into Filament’s events (e.g., AfterFormSaved) to react to combobox changes:
use Filament\Events\AfterFormSaved;
AfterFormSaved::listen(function (AfterFormSaved $event) {
if ($event->form->hasField('combobox_field')) {
// Handle logic
}
});
Localization: Override labels/placeholders via Filament’s localization system:
Combobox::make('field')
->label(__('filament-combobox::labels.custom_label'));
No Package Config:
The package relies entirely on Filament’s config. Check config/filament.php for global settings.
Asset Publishing: If extending views, publish assets:
php artisan vendor:publish --tag=filament-combobox-assets
How can I help you explore Laravel packages today?