检索上个月的所有行(Laravel + Eloquent)
我正在尝试获取属于上个月的所有记录,到目前为止我设法获取了上个月的所有记录,但到目前为止,我不确定如何仅获取上个月的记录
I'm trying to get all records that belongs to last month, so far I managed to get all from last month but to date today, I'm not sure how I can get only for last month
$revenueMonth = Callback::where('created_at', '>=', Carbon::today()->startOfMonth()->subMonth())->sum('payment');
推荐答案
更清晰的解决你的问题:
More clear solution for your problem:
$revenueMonth = Callback::whereMonth(
'created_at', '=', Carbon::now()->subMonth()->month
);
相关文章