QueenFruits/Backend/app/Http/Resources/Home/ProductByOutletResource.php

29 lines
799 B
PHP

<?php
namespace App\Http\Resources\Home;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class ProductByOutletResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->uuid,
'server_image_url' => Arr::last($this->server_image_url),
'name' => $this->name,
'total_sold' => (int) $this->total_sold,
'average_rating' => round($this->average_rating, 2),
'selling_price' => optional($this->variants->first()?->inventory)->selling_price,
'likes' => $this->likes_count ?? 0
];
}
}