-
|
I wrote filter:
I go to the datatable page, open Laravel debugbar and see 6 database queries including 5 duplicates. Why does this happen and how can it be prevented? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
That's because you create query See To solve this issue, you need to create For example public function leaveTypes(): array
{
return LeaveType::select(['id', 'name'])->pluck('name', 'id')->toArray();
}
public function filters(): array
{
return [
'leave' => Filter::make('Leave')->select($this->leaveTypes()),
];
} |
Beta Was this translation helpful? Give feedback.

That's because you create query
LeaveType::select(['id', 'name'])->pluck('name', 'id')->toArray())inside the filters method..See
WithFilters.phpfile here.To solve this issue, you need to create
queryoutside thefiltersmethod and place the result of yourqueryFor example