If you want to filter your records by Spatie Tags, then you can use the below snippet. It allows you to filter by one or multiple tags at the same time. In this example I use the type my-tag
and add the following code to the Resource
table section:
public static function table(Table $table): Table{ return $table ->columns([ // ... ]) ->filters([ SelectFilter::make('tags') ->multiple() ->options(Tag::getWithType('my-tag')->pluck('name', 'name')) ->query(function (Builder $query, array $data): Builder { return $query->when($data['values'], function (Builder $query, $data): Builder { return $query->withAnyTags(array_values($data), 'my-tag'); }); }) ]);}
Awesome trick. You can make them searchable also, but doesn't work with multiple tags.