public static function totalLength($userId)
{
$lengths = static::where('target_user_id', $userId)->select('cancel', DB::raw('SUM(length) as length'))->groupBy('cancel')->get();
$totalLength = 0;
foreach ($lengths as $length) {
if ($length->cancel !== true) {
$totalLength += $length->length;
} else {
$totalLength -= $length->length;
}
}
return $totalLength;
}