<?php

namespace App\Http\Resources\Api\Dashboard\Admin\WorkoutCategory;

use Illuminate\Http\Resources\Json\JsonResource;

class WorkoutCategoryResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        $locales = [];

        foreach (config('translatable.locales') as $locale) {
            $locales[$locale]['title']        = @$this->translate($locale)?->title;
        }
        return [
            'id'                 => $this->id,
            'title'              => $this->title,
        ] + $locales;
    }
}
