Rbex
Rbex

Reputation: 1539

Many to Many Get All Id Function Laravel 5.2

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;
}

Upvotes: 1

Views: 33

Answers (1)

KmasterYC
KmasterYC

Reputation: 2364

All you need. Btw try to research before asking

$item_ids = $subcategory->items->pluck('id');

Upvotes: 2

Related Questions