* @param \Illuminate\Http\Request $request * @return array */ public function toArray($request): array { return $this->collection->map(function ($category) { return [ 'category_id' => $category->id, 'title' => $category->title, 'slug' => $category->slug, 'description' => $category->description, 'cover' => $category->cover_url, 'pictures' => $category->pictures_url, 'created_at' => (string) $category->created_at, 'children' => new self($category->children), ]; })->toArray(); } }