检索上个月的所有行(Laravel + Eloquent)
2022-08-30 23:08:07
我试图获得属于上个月的所有记录,到目前为止,我设法从上个月获得了所有记录,但到目前为止,我不确定我如何只获得上个月的记录
$revenueMonth = Callback::where('created_at', '>=', Carbon::today()->startOfMonth()->subMonth())->sum('payment');
我试图获得属于上个月的所有记录,到目前为止,我设法从上个月获得了所有记录,但到目前为止,我不确定我如何只获得上个月的记录
$revenueMonth = Callback::where('created_at', '>=', Carbon::today()->startOfMonth()->subMonth())->sum('payment');
更清晰的解决方案:
$revenueMonth = Callback::whereMonth(
'created_at', '=', Carbon::now()->subMonth()->month
);
请尝试以下解决方案:
$revenueMonth = Callback::where(
'created_at', '>=', Carbon::now()->subDays(30)->toDateTimeString()
);
您将获得过去 30 天的所有回电。
$revenueMonth = Callback::where(
'created_at', '>=', Carbon::now()->firstOfMonth()->toDateTimeString()
);
获取当前月份。
$revenueMonth = Callback::where(
'created_at', '>=', Carbon::now()->startOfMonth()->subMonth()->toDateString()
);
上个月开始。
更新
$revenueMonth = Callback::where(
'created_at', '>=', Carbon::now()->subMonth()->toDateTimeString()
);
这就是你在寻找什么:)
希望它能帮助你:)