You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.3 KiB
48 lines
1.3 KiB
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\Resource;
|
|
|
|
class ProductResource extends Resource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
return [
|
|
'uuid' => (string)$this->uuid,
|
|
'name' => (string)$this->name,
|
|
'title' => (string)$this->title,
|
|
'price' => (double)$this->price,
|
|
'original_price' => (double)$this->original_price,
|
|
'thumb' => $this->thumb,
|
|
'sale_count' => (int)$this->sale_count,
|
|
'count' => (int)$this->count,
|
|
'view_count' => (int)$this->view_count,
|
|
'created_at' => (string)$this->created_at,
|
|
|
|
'content' => $this->whenLoaded('detail', function () {
|
|
|
|
return (string)optional($this->detail)->content;
|
|
}),
|
|
'pictures' => $this->whenLoaded('detail', function () {
|
|
|
|
return $this->assertPictures($this->pictures);
|
|
}),
|
|
];
|
|
}
|
|
|
|
protected function assertPictures($pictures)
|
|
{
|
|
return collect($pictures)->map(function ($uri) {
|
|
|
|
return assertUrl($uri);
|
|
});
|
|
}
|
|
}
|