Replies: 3 comments 13 replies
-
I see this one fairly often, the best way around it is to:
public array $spokenLanguages = [];
if (empty($this->spokenLanguages)) {
$this->spokenLanguages = SpokenLanguage::query()
->orderBy('name')
->pluck('name','id') // Note that I've added ID here so that you can use it in the filter.
->toArray();
}
MultiSelectFilter::make(__('cruds.spokenLanguage.title'), 'language')
->options(
$this->spokenLanguages
)->filter(function (Builder $builder, array $values) {
$builder->whereHas('spokenLanguages', fn($query) => $query->whereIn('spoken_languages.id', $values));
}), This will mean that you're only ever loading the filter options the one time. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Thanks for your answer, just curious why is it called so many times ? |
Beta Was this translation helpful? Give feedback.
12 replies
-
This should now be remediated, please re-open if it isn't! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I just discovered a strange behaviour, I used Debugbar to look at the DB request count, and was puzzled to see 202 requests on a very simple table.
I than removed my filter function, and I got 26 requests...
I finally add a Log::info in the filters() functions and it's been called around 70 times...
I don't have any boot or mount functions in this datatable.
Here is my filters function:
My builder function is:
Finally I had a look in my other datatables, and all have a similar behaviour...
Any idea ?
Thanks for your help.
Denis
Beta Was this translation helpful? Give feedback.
All reactions