'array', 'dimensione_file' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; /** * Relazione polimorfica */ public function documentable(): MorphTo { return $this->morphTo(); } /** * Scope per tipo documento */ public function scopeTipo($query, $tipo) { return $query->where('tipo_documento', $tipo); } /** * Accessor per URL download */ public function getUrlDownloadAttribute() { return route('admin.documenti.download', $this->id); } /** * Accessor per dimensione leggibile */ public function getDimensioneLeggibileAttribute() { $bytes = $this->dimensione_file; $units = ['B', 'KB', 'MB', 'GB']; for ($i = 0; $bytes > 1024; $i++) { $bytes /= 1024; } return round($bytes, 2) . ' ' . $units[$i]; } }