'boolean', ]; public function user(): BelongsTo { return $this->belongsTo(User::class); } public function name(): Attribute { return Attribute::make( get: fn () => $this->original_name ?? '', ); } public function thumbnailPath(): Attribute { return Attribute::make( get: function () { if (!$this->path || Str::contains(pathinfo($this->path, PATHINFO_FILENAME), '.thumbnail')) { return $this->path; } $directory = pathinfo($this->path, PATHINFO_DIRNAME); $filename = pathinfo($this->path, PATHINFO_FILENAME); $extension = pathinfo($this->path, PATHINFO_EXTENSION); $thumbnailName = $filename . '.thumbnail' . ($extension !== '' ? '.' . $extension : ''); return $directory === '.' ? $thumbnailName : $directory . '/' . $thumbnailName; }, ); } public function thumbnailLink(): Attribute { return Attribute::make( get: function () { $thumbnailPath = $this->thumbnail_path; if ($thumbnailPath && Storage::disk('public')->exists($thumbnailPath)) { return url('/storage/' . $thumbnailPath); } return $this->link; }, ); } public function isImage(): bool { return Str::startsWith(Str::lower((string) $this->mime_type), 'image/'); } public function iconClass(): string { $mimeType = Str::lower((string) $this->mime_type); return match (true) { Str::startsWith($mimeType, 'image/') => 'bi bi-file-earmark-image', $mimeType === 'application/pdf' => 'bi bi-file-earmark-pdf', $mimeType === 'application/msword', Str::contains($mimeType, 'wordprocessingml') => 'bi bi-file-earmark-word', $mimeType === 'application/vnd.ms-excel', Str::contains($mimeType, 'spreadsheetml') => 'bi bi-file-earmark-excel', $mimeType === 'application/vnd.ms-powerpoint', Str::contains($mimeType, 'presentationml') => 'bi bi-file-earmark-ppt', Str::startsWith($mimeType, 'audio/') => 'bi bi-file-earmark-music', Str::startsWith($mimeType, 'video/') => 'bi bi-file-earmark-play', Str::startsWith($mimeType, 'text/'), Str::contains($mimeType, 'json'), Str::contains($mimeType, 'xml') => 'bi bi-file-earmark-code', Str::contains($mimeType, 'zip'), Str::contains($mimeType, 'rar'), Str::contains($mimeType, '7z'), Str::contains($mimeType, 'gzip') => 'bi bi-file-earmark-zip', default => 'bi bi-file-earmark', }; } }