I'm attempting to calculate the sum of the differences between the 'from' and 'to' columns in the 'absences' table, but I'm encountering an error.
Column not found: 1054 Unknown column 'absences.hours_difference' in 'field list'
$classesAbsences = Classes::withSum([
'absences' => function ($query) {
$query->selectRaw('TIMESTAMPDIFF(HOUR, `from`, `to`) AS hours_difference');
}
], 'absences.hours_difference')
->get();