Deleted_at from and until with TrashedFilter

Hey! I was wondering if anyone have done this before or have had this issue but any help will be much appreciate it! I have a resource that has a TrashedFilter filter. I'm trying to implement another filter that will filter results by deleted_at from and deleted_at until. it seems that the filter works but only if I apply the trashedFilter 'only deleted records' is there a way that I can manually set that value when the deleted_from It's being used? I thought in removing the trashed filter but that led to more issues like it will display the deleted records. Here is the idea: TrashedFilter::make(), Filter::make('deleted_date_range') ->form([ DateTimePicker::make('deleted_from'), DateTimePicker::make('deleted_until'), ]) ->query(function ($query, array $data) { if ($data['deleted_from'] || $data['deleted_until']) { // Explicitly include only soft-deleted records doesn’t work $query->onlyTrashed(); if ($data['deleted_from']) { $query->whereDate('deleted_at', '>=', $data['deleted_from']); } if ($data['deleted_until']) { $query->whereDate('deleted_at', '<=', $data['deleted_until']); } } return $query; }), ])) public static function getEloquentQuery(): Builder { return parent::getEloquentQuery() ->withoutGlobalScopes([ SoftDeletingScope::class, ]); } Any other options or ideas will be very helpfull! thank you in advance!!
Solution:
@Dennis Koch thank you very much! That did gave me an idea! For anyone facing this issue or anything similar you can get a filters value using: $livewire->getTableFilterState($filterName)...
Jump to solution
5 Replies
Dennis Koch
Dennis Koch3mo ago
Check the code of the TrashedFilter it probably sets/unsets the SoftDeleting scope.
aleronal_
aleronal_OP3mo ago
Yeah it does! But I guess that’s necessary for the TrashedFilter! I’m wondering if there is any way of unsetting that filter when the other one it’s applied?
Dennis Koch
Dennis Koch3mo ago
You could maybe check whether another filter is applied from that filter via $livewire->filters
Solution
aleronal_
aleronal_3mo ago
@Dennis Koch thank you very much! That did gave me an idea! For anyone facing this issue or anything similar you can get a filters value using: $livewire->getTableFilterState($filterName) I ended up creating my own trashedFilter in which the default if (filter was set) just return the $query else $query->withoutTrashed()
Dennis Koch
Dennis Koch3mo ago
Great that you found a solution

Did you find this page helpful?