| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- declare(strict_types=1);
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- class DocumentationDocumentVersion extends Model
- {
- protected $fillable = [
- 'document_id',
- 'file_id',
- 'version',
- 'file_size',
- 'created_by',
- ];
- protected function casts(): array
- {
- return [
- 'version' => 'integer',
- 'file_size' => 'integer',
- ];
- }
- public function document(): BelongsTo
- {
- return $this->belongsTo(DocumentationDocument::class, 'document_id');
- }
- public function file(): BelongsTo
- {
- return $this->belongsTo(File::class);
- }
- public function creator(): BelongsTo
- {
- return $this->belongsTo(User::class, 'created_by');
- }
- public function isImage(): bool
- {
- return str_starts_with(strtolower((string) $this->file?->mime_type), 'image/');
- }
- public function iconClass(): string
- {
- $mimeType = strtolower((string) $this->file?->mime_type);
- return match (true) {
- str_starts_with($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_starts_with($mimeType, 'audio/') => 'bi bi-file-earmark-music',
- str_starts_with($mimeType, 'video/') => 'bi bi-file-earmark-play',
- str_starts_with($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',
- };
- }
- }
|