Reputation: 1539
Is there a function to get All the item_id in Many to Many relations.
$subcategory = $this->subcategory->find($id);
Or Do I need to do it manually. Basically I can do it but I hope there is an aggregate function.
$itemIds=[];
foreach($subcategory->items as $item){
$itemIds[] = $item->id;
}
Upvotes: 1
Views: 33
Reputation: 2364
All you need. Btw try to research before asking
$item_ids = $subcategory->items->pluck('id');
Upvotes: 2