Product::where([])->orderBy('num','desc');
Product::where([])->orderBy('click','desc');
我需要 类似以“click-num”排序
阿神2017-04-11 10:30:48
你可以使用orderByRaw(string $sql, array $bindings = array())
方法,直接把排序的sql写在第一个参数就可以了
怪我咯2017-04-11 10:30:48
-- mysql原語句
select (click-num) click_num from table order by click_num desc
// laravel寫法,如果ORM,則自行調整
DB::table('table)->selectRaw('(click-num) as click_num')->orderBy('click_num', 'desc')->get()
如果數據量大,以上性能會不佳,這塊自測吧!