© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
4 replies
acroninja

Select Filter with nested relation won't filter

public static function productFilter($relationship = 'lineItem.product'){
        return SelectFilter::make($relationship)
            ->label('Product')
            ->relationship($relationship, 'name')
            ->native(false)
            ->preload()
            ->searchable();
    }
public static function productFilter($relationship = 'lineItem.product'){
        return SelectFilter::make($relationship)
            ->label('Product')
            ->relationship($relationship, 'name')
            ->native(false)
            ->preload()
            ->searchable();
    }


If we use a direct relationship the select filter works
Nested relations provide the correct dropdown options but does not filter the results

If try to add a query or ->modifyQueryUsing $data array is never populated.

 ->query(function (Builder $query, array $data) use ($relationship) {
        if (isset($data['value'])) {
            $query->whereHas($relationship, function ($query) use ($data) {
                $query->where('id', $data['value']);
            });

        }
    })
 ->query(function (Builder $query, array $data) use ($relationship) {
        if (isset($data['value'])) {
            $query->whereHas($relationship, function ($query) use ($data) {
                $query->where('id', $data['value']);
            });

        }
    })


Also tried to create direct relation on the model like this but throws an error

  public function productCategory(): BelongsTo
  {
      return $this->product()->productCategory();
  }
  public function productCategory(): BelongsTo
  {
      return $this->product()->productCategory();
  }
Solution
Found the problem. the Select filter name needs to be the attribute name
product_category_id
product_category_id
like this:-

 public static function productCategoryFilter($relationship = 'product.productCategory'){
        return SelectFilter::make('product_category_id')
            ->label('Product Category')
            ->relationship($relationship, 'title')
            ->native(false)
            ->searchable()
            ->preload();
    }
 public static function productCategoryFilter($relationship = 'product.productCategory'){
        return SelectFilter::make('product_category_id')
            ->label('Product Category')
            ->relationship($relationship, 'title')
            ->native(false)
            ->searchable()
            ->preload();
    }
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Select Filter with relation
FilamentFFilament / ❓┊help
3y ago
Select filter grouping options in relation filter
FilamentFFilament / ❓┊help
3y ago
Select filter attribute name by relation
FilamentFFilament / ❓┊help
12mo ago
Nested relation
FilamentFFilament / ❓┊help
3y ago