【问题标题】:How to get data which has expiry date nearest to current date?如何获取到期日期最接近当前日期的数据?
【发布时间】:2021-07-27 09:40:42
【问题描述】:

我有 PurchaseOrderProduct 模型,我从中获取这样的数据

PurchaseOrderProduct::with('products')
                     ->with('warehouse_locations')
                     ->with('productStatuses')
                     ->with('purchase_orders')
                     ->where('product_id', $request->product_id)
                     ->where('free_qty', '>=', 1)
                     ->get();

现在在这个表中,我有 expiry_date 类型的列 date 我想获取最接近当前日期的数据 orderBy expiry_date

意味着purchase_order_product的到期日期最接近当前日期。

【问题讨论】:

  • 您的结果中是否需要过期产品或可以排除它们?

标签: laravel eloquent laravel-8 laravel-query-builder


【解决方案1】:
$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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-15
    • 1970-01-01
    相关资源
    最近更新 更多