ekart/backend/app/Http/Resources/CartItemResource.php
kusowl 1656739ecd feature: add and fetch products in cart api
- schema for cart and product
- define relationship, DTO, Resource and API collections
- Add post and get endpoint for cart api
2026-03-09 19:07:27 +05:30

32 lines
789 B
PHP

<?php
namespace App\Http\Resources;
use App\Data\CartItemDTO;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Storage;
/**
* @property CartItemDTO $resource
*/
class CartItemResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->resource->id,
'title' => $this->resource->title,
'quantity' => $this->resource->quantity,
'price' => $this->resource->price,
'subtotal' => $this->resource->subtotal,
'image' => Storage::disk('public')->url($this->resource->image),
];
}
}