我想获取pwra_dt
= $ month && $ year的数据。我能做什么?现在,它显示所有记录!
查询:
$purchaseOrder = PurchaseOrder::whereHas('pwra', function (Builder $query) use ($year, $month) {
$query->whereYear('pwra_dt', $year)
->whereMonth('pwra_dt', $month);
})
->get();
PurchaseOrder(Model)
public function pwra()
{
return $this->hasMany('App\Models\Pwra', 'purchase_order_uuid', 'purchase_order_uuid');
}
PWRA(模型)
public function purchaseOrder()
{
return $this->belongsTo('App\Models\PurchaseOrder', 'purchase_order_uuid', 'purchase_order_uuid');
}