在Laravel,Laravel 5中将集体转换为数组
问题描述:
How can I transform this collection to array and eject "whereNotIn" using a Laravel query, like this:
->whereNotIn('id', ['collection'])->get();'
Collection {#259 ▼
#items: array:3 [▼
0 => {#257 ▼
+"id": 2
}
1 => {#256 ▼
+"id": 3
}
2 => {#237 ▼
+"id": 6
}
]}
如何将此集合转换为数组并使用Laravel查询弹出“whereNotIn”,如下所示: p >
- > whereNotIn('id',['collection']) - > get();'
Collection {#259▼
#items:array :3 [▼
0 => {#257▼
+“id”:2
}
1 => {#256▼
+“id”:3
}
2 => {#237▼
+“id”:6
}
]}
code> pre>
div>
答
In fact, to get an array, you should use pluck
together with the all()
method, so in this case you should use:
->whereNotIn('id', $collection->pluck('id')->all())->get();