Php 使用count-Carbon[Laravel]仅检索最近几年的数据

Php 使用count-Carbon[Laravel]仅检索最近几年的数据,php,laravel,laravel-5,laravel-4,laravel-5.3,Php,Laravel,Laravel 5,Laravel 4,Laravel 5.3,我正在制作一个计数器,仅检索2017年的上一年数据。只从一月到十二月。我的下一个功能是subYears(1),以获取前几年的数据 现在我有, $intake = Intake::where('confirmed', 1) ->where('officiant_id', $this->id) ->whereIn('weddingStartDateTime', Carbon::now()-

我正在制作一个计数器,仅检索2017年的上一年数据。只从一月到十二月。我的下一个功能是
subYears(1)
,以获取前几年的数据

现在我有,

  $intake = Intake::where('confirmed', 1)
                      ->where('officiant_id', $this->id)
                       ->whereIn('weddingStartDateTime', Carbon::now()->format('Y') )
                      ->get();
(get将替换为一个
->计数
,我只是想显示它以供测试之用


如何仅获取过去几年的数据?必须是动态的。

Laravel的查询生成器具有以下功能:

$intake = Intake::where('confirmed', 1)
        ->where('officiant_id', $this->id)
        ->whereYear('weddingStartDateTime', Carbon::now()->format('Y'))
        ->get();

另一种方法是使用
whereBetween()


e、 g.
intraction::whereBetween('weddingStartDateTime',[$date1,$date2]);

我不喜欢这种方法。
whereYear()
方法是专门为这些场景设计的。是的,它非常适合这种情况,直到现在才知道。谢谢!