You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
696 B
32 lines
696 B
<?php
|
|
|
|
namespace App\Http\Resources\API\v2;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
use App\Models\Item;
|
|
|
|
class CategoryResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
$items = Item::where('category_id', $this->id)
|
|
->where('count', 0)
|
|
->get();
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'uuid' => $this->uuid,
|
|
'name' => $this->name,
|
|
'url' => $this->url,
|
|
'items' => ItemResource::collection($items)
|
|
];
|
|
}
|
|
}
|