File: D:/HostingSpaces/slenders/slenders.nl/app/Komma/Shop/Products/Product/ProductResource.php
<?php
namespace App\Komma\Shop\Products\Product;
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
{
/**
* 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,
'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)),
];
}
}