Skip to content

Duplicated database queries during filtering #565

Closed Answered by rizkhal
lukogites asked this question in Q&A
Discussion options

You must be logged in to vote

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 the filters method and place the result of your query

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()),
   ];
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@lukogites
Comment options

@rizkhal
Comment options

@lukogites
Comment options

Answer selected by lukogites
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants