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