Update CategoryResource to show only item templates.
This commit is contained in:
@@ -5,6 +5,8 @@ namespace App\Http\Resources\API\v2;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
use App\Models\Item;
|
||||||
|
|
||||||
class CategoryResource extends JsonResource
|
class CategoryResource extends JsonResource
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -14,12 +16,16 @@ class CategoryResource extends JsonResource
|
|||||||
*/
|
*/
|
||||||
public function toArray(Request $request): array
|
public function toArray(Request $request): array
|
||||||
{
|
{
|
||||||
|
$items = Item::where('category_id', $this->id)
|
||||||
|
->where('count', 0)
|
||||||
|
->get();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'uuid' => $this->uuid,
|
'uuid' => $this->uuid,
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'url' => $this->url,
|
'url' => $this->url,
|
||||||
'items' => ItemResource::collection($this->whenLoaded('items'))
|
'items' => ItemResource::collection($items)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user