feat(desfile): implement entry management with image handling and variant synchronization
This commit is contained in:
39
app/Domains/Desfile/Resources/EntryResource.php
Normal file
39
app/Domains/Desfile/Resources/EntryResource.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user