变量虽然包含值但未在查询中传递值

variable not passing value in query though it contains value

 public function Query()
{
    
    $total= User::get('e_id');
  //  dd($total);
    foreach($total as $totals){
     

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

        $s= User::whereMonth('date' , $month)->whereYear('date' , $year)->where('e_id' , $totals)->get()->sum('latehours');
        
        dd($s);
    }
  //  dd($totals);

}

在此代码中,变量 $totals 包含 'e_id' 的值,例如当我 dd($totals) 它显示值时,它从表单中获取的“a-2”例如“a-2”但是当我将它与 'e_id' 进行比较时,它会在变量 $s 中显示 'latehours' 的总和 null(0),而当我直接输入 'a-2' 时,它会总结记录'latehours' 反对这个 'e_id'。这里有什么问题?任何建议。提前致谢。

使用这个

$s= User::whereMonth('date' , $month)->whereYear('date' , $year)->where('e_id' , $totals->e_id)->get()->sum('latehours');

您正在传递 $totals 对象,其中条件将其更改为 $totals->e_id