2016-08-17 6 views
1

Many to Many 관계에서 모든 item_id를 가져 오는 함수가 있습니까? enter image description hereMany Many Many Id Function Laravel 5.2

$subcategory = $this->subcategory->find($id); 

또는 내가 수동으로 할 필요가 있는가. 기본적으로 할 수 있지만 집계 함수가 있기를 바랍니다.

$itemIds=[]; 
foreach($subcategory->items as $item){ 
    $itemIds[] = $item->id; 
} 
+0

답변을 요청하기 전에 연구하려고하는 것은 여기에 있습니다 : http://stackoverflow.com/questions/36593847/laravel-eloquent-get-all-records-wherehas-all-ids-in-many -to-many-relation – d3r1ck

답변

2

모두 필요합니다. BTW 질문의

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

나는 이미 연구했지만 찾지 못했습니다. 그래서 여기에서 제가 물었습니다. 그러나 어쨌든 고마워, 그것은 당신에게 많은 비용. – Rbex

+0

답변이 정상이면 투표를하고 답변을 수락합니다. – KmasterYC