remove where clause when table is filtered

I have a table and the basic query for the table has a filter condition of is_complete = 0. I want to have a filter that basically says, "Show completed", and when the user adds the filter, it removes the condition and just displays all the records. This seems like it would be easy, but I can't seem to get it to behave correctly.
public function table(Table $table): Table
{
return $table
->query($this->getData())
->columns([
...
])
->filters([
Filter::make('is_complete')->label('Recently Completed')
->query(fn (Builder $query): Builder => Model::where('location_id', $this->location->id))
->toggle()
]);
}

public function getData()
{
return Model::where('location_id', $this->location->id)->where('is_complete', 0);
}
public function table(Table $table): Table
{
return $table
->query($this->getData())
->columns([
...
])
->filters([
Filter::make('is_complete')->label('Recently Completed')
->query(fn (Builder $query): Builder => Model::where('location_id', $this->location->id))
->toggle()
]);
}

public function getData()
{
return Model::where('location_id', $this->location->id)->where('is_complete', 0);
}
It's sort of the opposite of a filter honestly...I dunno. I don't love it, but I don't know of a better solution.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server