*/ public function toArray(Request $request): array { return [ 'id' => $this->id, 'unit_id' => $this->unit_id, 'parent_id' => $this->parent_id, 'parent' => $this->whenLoaded('parent', fn () => $this->parent ? [ 'id' => $this->parent->id, 'code' => $this->parent->code, 'description' => $this->parent->description, 'chart_type' => $this->parent->chart_type, ] : null), 'code' => $this->code, 'order' => $this->order, 'description' => $this->description, 'chart_type' => $this->chart_type, 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'), 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'), ]; } /** * @param \Illuminate\Database\Eloquent\Collection $resource * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection */ public static function collection($resource): AnonymousResourceCollection { return parent::collection($resource); } }