'array', 'size' => 'integer', 'width' => 'integer', 'height' => 'integer', ]; } /** * @return BelongsTo */ public function uploader(): BelongsTo { return $this->belongsTo(User::class, 'uploaded_by'); } /** * @return HasMany */ public function usages(): HasMany { return $this->hasMany(MediaUsage::class); } public function fileExists(): bool { return Storage::disk($this->disk ?: 'uploads')->exists($this->path); } /** * Adresse des Bilds – null, wenn die Datei fehlt. * * @param string|null $variant „thumb“, „large“ oder null für das Original */ public function url(?string $variant = null): ?string { // „?v=“ folgt dem Änderungszeitpunkt der Datei (Ersetzen setzt ihn weiter) – so // haben Mediathek, Seiten und Beiträge dieselbe Adresse und teilen sich den Cache. return app(Images::class)->url($this->path, $variant); } public function displayName(): string { return $this->original_name ?: basename($this->path); } /** * Für Mediathek und Bildauswahl. * * @return array */ public function toLibraryArray(): array { $url = $this->url(); return [ 'id' => $this->id, 'path' => $this->path, 'url' => $url, 'thumb_url' => $url ? $this->url('thumb') : null, 'name' => $this->displayName(), 'alt' => $this->alt ?? '', 'caption' => $this->caption ?? '', 'tags' => $this->tags ?? [], 'mime' => $this->mime, 'size' => $this->size, 'width' => $this->width, 'height' => $this->height, 'missing' => $url === null, 'uploader' => $this->relationLoaded('uploader') && $this->uploader ? ['id' => $this->uploader->id, 'name' => $this->uploader->name] : null, 'usage_count' => $this->usages_count ?? null, 'created_at' => $this->created_at?->toIso8601String(), 'updated_at' => $this->updated_at?->toIso8601String(), ]; } }