Support the ongoing development of Laravel.io →
Scout Eloquent Testing
Last updated 2 years ago.

isaacongoma liked this thread

1

Hi Lucas.

You should be able to use the conditional clause on the builder to achieve this.

Your use-case would be something like this (untested):

$users = User::when($this->search, function ($query) {
    $query->search($this->search);
})
    ->orderBy($this->orderBy, $this->orderAsc ? 'ASC' : 'DESC')
    ->paginate($this->perPage);

lucasjose501, mrkalmdn liked this reply

2

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.