initial commit

This commit is contained in:
I-Fun
2026-04-01 08:04:56 +07:00
commit e09c8a5fa9
111 changed files with 18022 additions and 0 deletions

51
app/Models/MediaFile.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Storage;
class MediaFile extends Model
{
use SoftDeletes;
protected $fillable = [
'client_id', 'name', 'original_name', 'path', 'disk', 'mime_type', 'size', 'folder', 'description',
];
public function client(): BelongsTo
{
return $this->belongsTo(Client::class);
}
public function getUrlAttribute(): string
{
return route('files.serve', $this->id);
}
public function getHumanSizeAttribute(): string
{
$bytes = $this->size;
if ($bytes >= 1073741824) return round($bytes / 1073741824, 2) . ' GB';
if ($bytes >= 1048576) return round($bytes / 1048576, 2) . ' MB';
if ($bytes >= 1024) return round($bytes / 1024, 2) . ' KB';
return $bytes . ' B';
}
public function getIsImageAttribute(): bool
{
return str_starts_with($this->mime_type, 'image/');
}
public function getIconAttribute(): string
{
if ($this->is_image) return '🖼️';
if (str_starts_with($this->mime_type, 'video/')) return '🎬';
if (str_contains($this->mime_type, 'pdf')) return '📄';
return '📁';
}
}