<?php

namespace Modules\Mall\Http\Resources\Api\Category;

use Illuminate\Http\Resources\Json\JsonResource;

class CategoryResource extends JsonResource
{

    public function toArray($request): array
    {
        return [
            'category_id' => $this->id,
            'name'        => $this->name,
            'cover'       => $this->cover_url,
            'children'    => $this->when(!$this->children()->shown()->get()->isEmpty(), function () {
                return self::collection($this->children()->shown()->get());
            }),
        ];
    }

}
