presseportale/app/Http/Resources/CategoryResource.php
Kevin Adametz 5b8bdf4182
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run
12-05-2026 Frontend dev
2026-05-12 18:32:33 +02:00

36 lines
1 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class CategoryResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'legacy' => [
'portal' => $this->legacy_portal,
'id' => $this->legacy_id,
],
'portal' => $this->portal?->value,
'is_active' => $this->is_active,
'translations' => $this->whenLoaded('translations', fn () => $this->translations
->mapWithKeys(fn ($translation) => [
$translation->locale => [
'name' => $translation->name,
'slug' => $translation->slug,
'description' => $translation->description,
],
])
->all()),
];
}
}