- schema for cart and product - define relationship, DTO, Resource and API collections - Add post and get endpoint for cart api
33 lines
720 B
PHP
33 lines
720 B
PHP
<?php
|
|
|
|
namespace App\Data;
|
|
|
|
use App\Contracts\OutputDataTransferObject;
|
|
|
|
final readonly class CartItemDTO implements OutputDataTransferObject
|
|
{
|
|
public function __construct(
|
|
public int $id,
|
|
public string $title,
|
|
public int $quantity,
|
|
public float $price,
|
|
public float $subtotal,
|
|
public string $image
|
|
) {}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'title' => $this->title,
|
|
'quantity' => $this->quantity,
|
|
'price' => $this->price,
|
|
'subtotal' => $this->subtotal,
|
|
'image' => $this->image,
|
|
];
|
|
}
|
|
}
|