Downloading files, calculating video size.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Carbon\Traits\Date;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -16,6 +17,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
* @property integer $numberofchapters
|
||||
* @property integer $timeswatched
|
||||
* @property Date $published_at
|
||||
* @property Chapter[] $chapters
|
||||
*/
|
||||
class Course extends Model
|
||||
{
|
||||
@@ -39,4 +41,22 @@ class Course extends Model
|
||||
{
|
||||
return $this->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;
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user