- schema for cart and product - define relationship, DTO, Resource and API collections - Add post and get endpoint for cart api
31 lines
684 B
PHP
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),
|
|
];
|
|
}
|
|
}
|