JezK
Edit File: Media.php
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; class Media extends Model { use HasFactory; protected $fillable = [ 'user_id', 'filename', 'original_name', 'path', 'disk', 'mime_type', 'size', 'alt_text', 'width', 'height', ]; protected function casts(): array { return [ 'size' => 'integer', 'width' => 'integer', 'height' => 'integer', ]; } public function user(): BelongsTo { return $this->belongsTo(User::class); } public function getUrlAttribute(): string { return asset('storage/' . $this->path); } public function getHumanSizeAttribute(): string { $bytes = $this->size; $units = ['B', 'KB', 'MB', 'GB']; $i = 0; while ($bytes >= 1024 && $i < count($units) - 1) { $bytes /= 1024; $i++; } return round($bytes, 2) . ' ' . $units[$i]; } public function isImage(): bool { return str_starts_with($this->mime_type ?? '', 'image/'); } }