27 lines
666 B
PHP
27 lines
666 B
PHP
<?php
|
|
|
|
namespace Peidikeji\Goods\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Support\Str;
|
|
|
|
class GoodsCategoryResource extends JsonResource
|
|
{
|
|
public function toArray($request)
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'name' => $this->name,
|
|
'image' => $this->image,
|
|
'parent_id' => $this->parent_id,
|
|
'level' => $this->level,
|
|
'sort' => $this->sort,
|
|
'path' => $this->path,
|
|
|
|
'children' => static::collection($this->whenLoaded('children')),
|
|
|
|
'type' => Str::startsWith($this->path, '-2-') ? 'shop' : '',
|
|
];
|
|
}
|
|
}
|