New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow defaultSort to accept Livewire #12687
Allow defaultSort to accept Livewire #12687
Conversation
Is there a way to refactor |
Hi Dan, I refactored this to a single I guess if there were any app/plugins that tapping into one of these methods (cough cough AdvancedTables), this would be a breaking change...not sure how you want to handle that. Finally, I did notice that inside if ($defaultSort instanceof Closure) {
app()->call($defaultSort, [
'direction' => $sortDirection,
'query' => $query,
]);
return $query;
} the ->defaultSort(fn (Builder $query) => $query->orderBy('status'), 'desc') doesn't sort the table by ->defaultSort(fn (Builder $query) => $query->orderBy('status', 'desc')) Just wanted you to know. |
It is only useful when using a string column, not a query function. If you pass a column name, it does apply. If you pass a query function, you need to accept |
hmmm...but when passing a column name, the column and sort direction was applied to the query before it reached this method. And when it was a query and reached this method then it wouldn't be applied...at least in my testing. Want to make sure I'm testing against all the different scenarios to make sure this isn't breaking anything. |
Just tested and the second param does still seem to work when passing a column name like |
Thanks for your help here! |
Yes, that all works fine. I'm referring to something different: public function getDefaultSort(Builder $query, string $direction): string | Builder | null
{
return $this->evaluate($this->defaultSort, [
'direction' => $direction, // this line doesn't appear to do anything
'query' => $query,
]);
} Evaluating So my question is, since it appears that |
It gives the user access to it:
If they are sharing the function between multiple |
Description
This PR allows
defaultSort()
to accept Livewire as a closure.Of course passing in Builder or a string continues to work as well.
Note: my first attempt was to keep the original condition and then evaluate the closure inside
getDefaultSortQuery()
, howeverapplyDefaultSortingToTableQuery()
callsgetDefaultSortColumn()
beforegetDefaultSortQuery()
so we have to evaluate there. This turned out to be cleaner anyway.composer cs
command.