Mar 26, 2020
0
Level 1
How to orderBy aliased column of relations model using Eloquent
How to get all warehouses matched where conditions and ordered by warehouse that has lowest price product.
This is my tables.
warehouses => [id]
products => [ id, warehouse_id, price ]
This is what I try to do. I dont known what correct syntax should be.
Warehouses::with('products')->where(...)->whereHas(...)
->select(['*', DB::raw('GROUP BY products.id .... MIN(products.price) as warehouse_min_product_price')])
->orderBy('warehouse_min_product_price', 'asc');
Thanks.
Please or to participate in this conversation.