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

isaacongoma liked this thread


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) {
    ->orderBy($this->orderBy, $this->orderAsc ? 'ASC' : 'DESC')

lucasjose501, mrkalmdn liked this reply


Sign in to participate in this thread!


Your banner here too?


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

Your logo here?

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

© 2024 - All rights reserved.