比较类型为 'date' 的 table 列与类型为 'month' 的变量

compare table column having type 'date' with variable having type 'month'

 public function collection()
{
   // dd($this->month);
    return User::whereMonth('date' , $this->month)->get();
}

我想比较 table 的日期类型与月份和年份。 $this->month 的格式是 "2021-03" 'date' 的格式是“2021-03-25”。 我如何比较两者。 提前致谢

同时使用 whereMonthwhereYear

[$year, $month] = explode('-', $this->month);

return User::query()
    ->whereMonth('date', (int) $month)
    ->whereYear('date', (int) $year)
    ->get();