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

31 lines
957 B
PHP

<?php
namespace App\Endpoint\Api\Http\Resources\Dealer;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductResource 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,
'name' => $this->name,
'unit' => $this->unit,
'cover' => (string) $this->cover,
'images' => $this->images,
'price' => (string) $this->price,
'is_online' => $this->isOnline(),
'description' => (string) $this->description,
'lvl_rules' => ProductLvlRuleResource::collection($this->whenLoaded('lvlRules')),
'sale_rules' => ProductSaleRuleResource::collection($this->whenLoaded('saleRules')),
];
}
}