33 lines
1.0 KiB
PHP
33 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources\Api\Admin;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class ProductResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
$minPrice = $this->whenLoaded('pricings', function () {
|
|
return $this->pricings->min('price');
|
|
});
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'uuid' => $this->uuid,
|
|
'name' => $this->name,
|
|
'product_type' => $this->product_type,
|
|
'category' => $this->whenLoaded('category', fn() => $this->category?->name),
|
|
'cpu' => $this->cpu,
|
|
'ram' => $this->ram,
|
|
'disk' => $this->disk,
|
|
'bandwidth' => $this->bandwidth,
|
|
'setup_fee' => $this->setup_fee,
|
|
'min_price' => $minPrice,
|
|
'is_active' => $this->is_active,
|
|
'created_at' => $this->created_at,
|
|
];
|
|
}
|
|
}
|