presseportale/app/Http/Resources/PressReleaseImageResource.php
Kevin Adametz 5b8bdf4182
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run
12-05-2026 Frontend dev
2026-05-12 18:32:33 +02:00

46 lines
1.4 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PressReleaseImageResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$variants = is_array($this->variants) ? $this->variants : [];
$variantUrls = [];
foreach ($variants as $key => $relativePath) {
if (is_string($relativePath) && filled($relativePath)) {
$variantUrls[$key] = asset('storage/'.ltrim($relativePath, '/'));
}
}
return [
'id' => $this->id,
'press_release_id' => $this->press_release_id,
'url' => $this->url(),
'urls' => array_merge(['original' => $this->url()], $variantUrls),
'variants' => $variants,
'disk' => $this->disk,
'path' => $this->path,
'title' => $this->title,
'description' => $this->description,
'copyright' => $this->copyright,
'is_preview' => $this->is_preview,
'sort_order' => $this->sort_order,
'width' => $this->width,
'height' => $this->height,
'mime' => $this->mime,
'created_at' => $this->created_at?->toIso8601String(),
'updated_at' => $this->updated_at?->toIso8601String(),
];
}
}