Nik*_*Nik 1 mysql laravel eloquent
我有一张表,如下所示:
ID | Month | Year | Data
1 | 01 | 2019 | 125
2 | 09 | 2019 | 133
3 | 09 | 2017 | 356
4 | 12 | 2018 | 567
5 | 10 | 2020 | 123
Run Code Online (Sandbox Code Playgroud)
我想获取12-2018到09-2019之间的行。
所以我有价值观
开始月份 = 12,
开始年份 = 2018,
月末 = 09
结束年份 = 2019 年。
我如何过滤之间的数据?
这是我到目前为止所拥有的:
$data = Revenue::where('month', '>=', $fromMonth)
->where('month', '<=', $toMonth)
->where('year', '>=', $fromYear)
->where('year', '<=', $toYear)
->orderBy('id', 'asc')
->paginate(6);
Run Code Online (Sandbox Code Playgroud)
在这里使用whereBetween方法
Revenue::whereBetween('year', [$fromYear, $toYear])
->whereBetween('month', [$fromMonth, $toMonth])
->orderBy('id', 'asc')
->paginate(6);
Run Code Online (Sandbox Code Playgroud)