© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
1 reply
Abi

Modify query for Select Element on form with relationship based on another form element

I have 2
Select
Select
components on the form.
Item Category
Item Category
and
Vendor
Vendor
. both these fields have
belongsToMany
belongsToMany
relationship with a pivot table
category_vendor
category_vendor
that stores vendors for each category or categories for a vendor. When a user selects a category, I want to display a list of vendors for that category and I am trying to use the
modifyQueryUsing
modifyQueryUsing
parameter for the
relationship
relationship
method on the
vendor
vendor
field. How do I pass the selected category to the
vendor
vendor
fields query parameter?
Select::make('item_category_id')
    ->relationship('itemCategory', 'name')
    ->createOptionAction(fn (Action $action) => $action->modalWidth('sm'))
    ->createOptionForm([
        TextInput::make('name')
            ->label('Name')
            ->required(),
    ])
    ->preload()
    ->columnSpanFull()
    ->searchable()
    ->live()
    ->required(),

Select::make('vendor_id')
    ->relationship('vendor', 'name', fn ($query) => $query->whereHas('categories', '?')),
Select::make('item_category_id')
    ->relationship('itemCategory', 'name')
    ->createOptionAction(fn (Action $action) => $action->modalWidth('sm'))
    ->createOptionForm([
        TextInput::make('name')
            ->label('Name')
            ->required(),
    ])
    ->preload()
    ->columnSpanFull()
    ->searchable()
    ->live()
    ->required(),

Select::make('vendor_id')
    ->relationship('vendor', 'name', fn ($query) => $query->whereHas('categories', '?')),
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Select Relationship Modify Query Using
FilamentFFilament / ❓┊help
2y ago
Modify SelectFilter query based on another SelectFilters value (Dependent Filters)
FilamentFFilament / ❓┊help
3y ago
Exporter: Modify Query based on Options?
FilamentFFilament / ❓┊help
2y ago
Modify Query Using nested relationship
FilamentFFilament / ❓┊help
2y ago