44 lines
1.3 KiB
PHP
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(),
|
|
];
|
|
}
|
|
}
|