Files
landing-api/app/Http/Resources/MediaResource.php
Josep Piguillem 4c4a2b3299
Some checks failed
Tests / lint (push) Has been cancelled
Tests / test (push) Has been cancelled
Tests / test-postgres (push) Has been cancelled
Tests / mcp (push) Has been cancelled
Browse and clean up the media library through the API
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 19:55:03 +02:00

44 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Resources;
use App\Models\Media;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin Media
*/
class MediaResource extends JsonResource
{
/**
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
// What a record stores — `featured_image` on a page — and so the one
// field a caller has to keep.
'path' => $this->path,
'url' => $this->url(),
'mime' => $this->mime,
'size' => $this->size,
'width' => $this->width,
'height' => $this->height,
// False until the queue has derived the smaller versions and the
// placeholder. The image serves either way.
'processed' => $this->isProcessed(),
'error' => $this->error,
// Only in the library, where it decides whether a file may go.
'referenced' => $this->when(
array_key_exists('referenced', $this->resource->getAttributes()),
fn () => (bool) $this->resource->getAttribute('referenced'),
),
'created_at' => $this->created_at?->toIso8601String(),
];
}
}