ekart/backend/app/Http/Resources/CartResource.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

31 lines
684 B
PHP

<?php
namespace App\Http\Resources;
use App\Data\CartDTO;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @property CartDTO $resource
*/
class CartResource extends JsonResource
{
public static $wrap = null;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->resource->id,
'itemsCount' => $this->resource->itemsCount,
'totalPrice' => $this->resource->totalPrice,
'items' => CartItemResource::collection($this->resource->items),
];
}
}