HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/stafa.komma.pro/app/Komma/Shop/Products/Product/ProductResource.php
<?php

namespace App\Komma\Shop\Products\Product;

use App\Komma\Globalization\RegionInfo;
use App\Komma\Shop\Products\ProductGroup\ProductGroup;
use App\Komma\Shop\Products\ProductGroup\ProductGroupResource;
use Illuminate\Http\Resources\Json\Resource;

/**
 * Class ProductResource
 *
 * @see Product
 * @see ProductGroup
 * @see ProductTranslation
 *
 * @package App\Komma\Shop\Products\Product
 */
class ProductResource extends Resource
{
    public function __construct($resource)
    {
        $this->regionInfo = new RegionInfo('NL');
        parent::__construct($resource);
    }

    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @see Product
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'active' => $this->active,
            'price' => $this->price,
            'price_formatted' => $this->regionInfo->getNumberFormat()->centsToCurrency($this->price, true, true),
            'stock_keeping_unit' => $this->stock_keeping_unit,
            'groups' => $this->whenLoaded('groups', ProductGroupResource::collection($this->groups)),
            'translation' => $this->whenLoaded('translation', new ProductTranslationResource($this->translation)),
            'translations' => $this->whenLoaded('translations', ProductTranslationResource::collection($this->translations)),
        ];
    }
}