F
Filamentβ€’2y ago
Husky110

Filtervalue in query

Hi - I want to create a select-filter where a user can filter any data that has not been updated within in the last 12, 24 or 48 hours, which then would modify the query like where('updated_at', '<=', Carbon::now()->subtractHours($x)); now I got as far that I would have to modify the query-function, but so far I've only seen it like fn($query) => $query->where('xyz', 'abc') how do I add the current filter value to that? Utilizing the whole formbuilder-component seems a bit overkill here. Is there an easy way?
8 Replies
Husky110
Husky110OPβ€’2y ago
"Utilizing the whole formbuilder-component seems a bit overkill here." -> which is why I was asking if there is an easy way for this. So is your answer "no - there is no easier way"? This is what I have so far:
Tables\Filters\SelectFilter::make('long_open') ->label('mylabel')
->options([0,12,24,48,72,96])
->default(0)
->query(fn($query) => $query->where([
['updated_at', '<', 'WHATEVER']
]))
Tables\Filters\SelectFilter::make('long_open') ->label('mylabel')
->options([0,12,24,48,72,96])
->default(0)
->query(fn($query) => $query->where([
['updated_at', '<', 'WHATEVER']
]))
Vp
Vpβ€’2y ago
"Utilizing the whole formbuilder-component seems a bit overkill here." I didn't read clearly this part, sorry.. and I don't know the easiest way for now
Husky110
Husky110OPβ€’2y ago
No worries - I appreciate your response anyhow. πŸ™‚ πŸ‘
awcodes
awcodesβ€’2y ago
This is exactly what custom filters are for. This is more complicated than a simple value = something use case which is what most filters are.
Husky110
Husky110OPβ€’2y ago
Ah okay - so the complication arises from the filter itself. I see.
awcodes
awcodesβ€’2y ago
The example on the docs is basically this exact use case. πŸ˜…
Husky110
Husky110OPβ€’2y ago
Yep - but I don't know what went through you guys minds and it's already established that the functions themselfs (I speak of the plain PHP) are not really good documentated, so just in case I am missing something obvious - I just ask. πŸ™‚
Want results from more Discord servers?
Add your server