Reputation: 571
I have PurchaseOrderProduct
Model from which I am getting data like that
PurchaseOrderProduct::with('products')
->with('warehouse_locations')
->with('productStatuses')
->with('purchase_orders')
->where('product_id', $request->product_id)
->where('free_qty', '>=', 1)
->get();
Now in this table, I have the column expiry_date
of type date
i want to fetch data orderBy
expiry_date
nearest to the current date .
Means purchase_order_product
whose expiry date is nearest to current date should come first.
Upvotes: 3
Views: 3014
Reputation: 4459
$product = PurchaseOrderProduct::with('products')
->with('warehouse_locations')
->with('productStatuses')
->with('purchase_orders')
->where('product_id', $request->product_id)
->where('free_qty', '>=', 1)
->whereDate('expiry_date', '>', Carbon::now())
->orderBy('expiry_date','asc')
->get();
Upvotes: 5