40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Desfile\Resources;
|
|
|
|
use App\Domains\Catalog\Models\CatalogItem;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
/** @mixin CatalogItem */
|
|
class EntryResource extends JsonResource
|
|
{
|
|
/** @return array<string, mixed> */
|
|
public function toArray(Request $request): array
|
|
{
|
|
$image = $this->allAttachments->first();
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'variants' => $this->variants->map(function ($variant): array {
|
|
$values = $variant->selectionValues();
|
|
|
|
return [
|
|
'id' => $variant->id,
|
|
'type' => $values->get('tipo'),
|
|
'sector' => $values->get('sector'),
|
|
'row' => $values->get('fila'),
|
|
'seat' => $values->get('asiento'),
|
|
'price' => number_format($variant->getPrice(), 2, '.', ''),
|
|
];
|
|
})->values(),
|
|
'image' => $image === null ? null : [
|
|
'key' => $image->key,
|
|
'filename' => $image->filename,
|
|
'url' => $image->getTemporaryUrl(1440),
|
|
'is_enabled' => (bool) $image->pivot->is_enabled,
|
|
],
|
|
];
|
|
}
|
|
}
|