1

プロジェクトでフィルター関数を作成しています。

「最新のものを表示」、「最も古いものを表示」などのフィルターオプションがあります。条件付きの where 句を実装する方法を見つけましたが、条件付きの orderBy クラスはないようです。

私の条件句は次のようになります。

$query->where(function($query) use ($request){
   if( ! empty($request->input('prices')) ){
      $opts = $request->prices;
      $query->where('price_id', $opts[0]);
   }
})

->orderBy でもこれを行う方法はありますか?

アップデート

return Auction::where('end_date', '>', Carbon::now() )
         ->where('locale', $locale)
         ->where('sold', 0)
         ->where(function($query) use ($request){

             if( ! empty($request->input('prices')) ){
                  $opts = $request->prices;
                  $query->where('price_id', $opts[0]);
             }
         })->paginate(8);

雄弁な方法でそれを行うにはどうすればよいですか?

4

1 に答える 1