27 lines
763 B
PHP
27 lines
763 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\FlashSale\Resources;
|
|
|
|
use App\Http\Controllers\Api\V1\Product\Resources\ProductIndexResource;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class FlashSaleResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->whenHas('id'),
|
|
'title' => $this->whenHas('title'),
|
|
'starts_at' => $this->starts_at?->toISOString(),
|
|
'ends_at' => $this->ends_at?->toISOString(),
|
|
'products' => ProductIndexResource::collection($this->whenLoaded('products')),
|
|
];
|
|
}
|
|
}
|