【发布时间】:2020-09-06 12:58:38
【问题描述】:
我想按价格订购我的所有产品。在 Product 表中有 product_options 列,在该列内我有 json 数据,类似这样;
{"price":390,"discounted_price":26,"quantity":168}
我尝试通过 product_options 订购,但它按字母顺序返回,所以 17 在 1000 之后。看起来我应该为此使用集合函数,但我真的很陌生。
$searchData = DB::table('posts')->where('type','=','product')->whereNotNull('product_options')->orderBy('product_options->price')->get();
有人可以帮帮我吗?
【问题讨论】:
-
这能回答你的问题吗? how to sort a json object in laravel
-
没有。它是一个数组,我有来自查询的对象,我想按价格对所有对象进行排序
标签: laravel sorting collections