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/veltech.komma.pro/app/Komma/Kms/JsonApi/TranslationResource.php
<?php

namespace App\Komma\Kms\JsonApi;

use App\Helpers\KommaHelpers;
use App\Komma\Kms\Core\AbstractTranslationModel;
use Illuminate\Http\Resources\Json\Resource;

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();

        foreach ($attributes as $index => $attribute) {
            if(is_array($attribute)) array_splice($attributes, $index, 1);
        }

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

        return $data;
    }

}