*/ protected $fillable = [ 'documentation_document_id', 'disk', 'path', 'original_name', 'mime_type', 'size', 'uploaded_by', ]; /** @var array */ protected $casts = [ 'size' => 'integer', ]; /** * Owning document. * * @return BelongsTo */ public function document(): BelongsTo { return $this->belongsTo(DocumentationDocument::class, 'documentation_document_id'); } /** * Return a readable file size label. */ public function getSizeLabelAttribute(): string { $bytes = (int) $this->size; $label = number_format($bytes / 1048576, 1) . ' MB'; if ($bytes <= 0) { $label = 'Unknown size'; } elseif ($bytes < 1024) { $label = $bytes . ' B'; } elseif ($bytes < 1048576) { $label = number_format($bytes / 1024, 1) . ' KB'; } return $label; } }