[英]How can I make select in select on laravel eloquent?
I use laravel 5.3 我使用laravel 5.3
My sql query is like this : 我的SQL查询是这样的:
SELECT *
FROM (
SELECT *
FROM products
WHERE `status` = 1 AND `stock` > 0 AND category_id = 5
ORDER BY updated_at DESC
LIMIT 4
) AS product
GROUP BY store_id
I want to change it to be laravel eloquent 我想将其更改为Laravel雄辩
But I'm still confused 但是我还是很困惑
How can I do it? 我该怎么做?
If you have Product model, you can run 如果您具有产品模型,则可以运行
$products = Product::where('status', 1)
->where('stock', '>', 0)
->where('category_id', '=', 5)
->groupBy('store_id')
->orderBy('updated_at', 'desc')
->take(4)
->get();
I think this should give you the same result since you pull everything from your derived table. 我认为这应该给您相同的结果,因为您从派生表中提取了所有内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.