Calculating the sum of differences between two columns in Laravel

49 views Asked by At

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();
0

There are 0 answers