Support the ongoing development of →
Scout Eloquent Testing
Last updated 10 months ago.

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')

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.

© 2023 - All rights reserved.