1

Is there a function to get All the item_id in Many to Many relations. enter image description here

$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;
}
Rbex
  • 1,519
  • 6
  • 24
  • 50
  • Answer of your question is here: http://stackoverflow.com/questions/36593847/laravel-eloquent-get-all-records-wherehas-all-ids-in-many-to-many-relation – Derick Alangi Aug 17 '16 at 02:58

1 Answers1

2

All you need. Btw try to research before asking

$item_ids = $subcategory->items->pluck('id');
KmasterYC
  • 2,294
  • 11
  • 19
  • I did already a research but haven't found it, that's the reason why I asked it here. But anyway thanks, it cost you a lot. – Rbex Aug 17 '16 at 03:09
  • If answer is ok, vote up and accept answer are always appriciated – KmasterYC Aug 17 '16 at 04:54