File: D:/HostingSpaces/stafa/werkenbijstafa.nl/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;
}
}