45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class AuditionEtude extends Model
|
|
{
|
|
protected $fillable = [
|
|
'instrument_id', 'auditioned_ensemble_id', 'set', 'original_filename', 'file_path', 'file_size',
|
|
];
|
|
|
|
public function instrument(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Instrument::class);
|
|
}
|
|
|
|
public function auditionedEnsemble(): BelongsTo
|
|
{
|
|
return $this->belongsTo(AuditionedEnsemble::class);
|
|
}
|
|
|
|
protected function humanReadableFileSize(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: function () {
|
|
$bytes = $this->file_size;
|
|
if ($bytes === null) {
|
|
return 'N/A';
|
|
}
|
|
|
|
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
$bytes = max($bytes, 0);
|
|
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
|
|
$pow = min($pow, count($units) - 1);
|
|
$bytes /= pow(1024, $pow);
|
|
|
|
return round($bytes, 2).' '.$units[$pow];
|
|
}
|
|
);
|
|
}
|
|
}
|