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/shop.komma.nl/app/JsonApi/TranslationResource.php
<?php

namespace App\JsonApi;

use App\Properties\Models\PropertizableTrait;
use Illuminate\Http\Resources\Json\Resource;
use Komma\KMS\Core\AbstractTranslationModel;
use Komma\KMS\Helpers\KommaHelpers;
use Laravelium\Sitemap\Model;

/**
 * @mixin Model|PropertizableTrait
 */
class TranslationResource extends Resource
{
    public function __construct($resource)
    {
        if(!is_a($resource,AbstractTranslationModel::class)) throw new \InvalidArgumentException('The resource must be an instance of '.AbstractTranslationModel::class);
        parent::__construct($resource);
    }

    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $attributes = $this->resource->toArray();
        if(array_key_exists('id', $attributes))

        $data = [
            'id' => (string) $this->id,
            'type' => KommaHelpers::getShortNameFromClass($this->resource, true),
            'attributes' => $attributes,
            'relationships' => []
        ];

        return $data;
    }

}