检索上个月的所有行(Laravel + Eloquent) [英] Retrive all rows from last month (Laravel + Eloquent)

查看:25
本文介绍了检索上个月的所有行(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
);

这篇关于检索上个月的所有行(Laravel + Eloquent)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆