*/ 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; if ($bytes <= 0) { return 'Unknown size'; } if ($bytes < 1024) { return $bytes . ' B'; } if ($bytes < 1048576) { return number_format($bytes / 1024, 1) . ' KB'; } return number_format($bytes / 1048576, 1) . ' MB'; } }