| 123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace App\Http\Resources;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- class StoreItemResource extends JsonResource
- {
- public function toArray(Request $request): array
- {
- return [
- 'id' => $this->id,
- 'name' => $this->name,
- 'description' => $this->description,
- 'category_id' => $this->category_id,
- 'category' => $this->whenLoaded('category', fn() => new CategoryResource($this->category)),
- 'price' => $this->price,
- 'associate_price' => $this->associate_price,
- 'supplier_price' => $this->supplier_price,
- 'size_s' => $this->size_s,
- 'stock_s' => $this->stock_s,
- 'size_m' => $this->size_m,
- 'stock_m' => $this->stock_m,
- 'size_l' => $this->size_l,
- 'stock_l' => $this->stock_l,
- 'size_xl' => $this->size_xl,
- 'stock_xl' => $this->stock_xl,
- 'status' => $this->status,
- 'media' => $this->whenLoaded('media', fn() => MediaResource::collection($this->media)),
- 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
- 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
- ];
- }
- }
|