I have a hasMany relation on my user model
public function timesheet()
{
return $this->hasMany('App\TimeTable', 'employee');
}
and I would like to have the sum of a column
$users = User::with('timesheet')->get();
foreach($users as $user) {
//sume of $user->timesheet
//tried $user->timesheet->sum('minutes') which return on each iteration 0
}
What is the best approach to get the right result?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire