6
0
Fork 0
jiqu-library-server/app/Endpoint/Api/Http/Resources/ShoppingCartItemResource.php

39 lines
1.1 KiB
PHP

<?php
namespace App\Endpoint\Api\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class ShoppingCartItemResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
'id' => $this->id,
'sku' => $this->when($this->relationLoaded('sku'), function () {
if ($this->sku) {
return ProductSkuSimpleResource::make($this->sku);
}
return [
'id' => $this->id,
'name' => $this->name,
'cover' => (string) $this->cover,
'sell_price' => $this->sell_price_format,
'vip_price' => (string) $this->vip_price_format,
'specs' => array_values((array) $this->specs),
'stock' => 0,
'is_online' => false,
];
}),
'quantity' => $this->quantity,
];
}
}