hasMany(Chapter::class); } public function totalSize(): Attribute { return Attribute::make( get: fn() => $this->chapters->sum('video_size'), ); } public function totalSizeHuman(): Attribute { return Attribute::make( get: function () { $base = log($this->total_size) / log(1024); $suffix = ["", "k", "M", "G", "T"][floor($base)]; return round(pow(1024, $base - floor($base)), 2) . $suffix; }, ); } }