-
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.php
file here.To solve this issue, you need to create
query
outside thefilters
method and place the result of yourquery
For example