简体   繁体   English

在Laravel,Laravel 5中将集体转换为数组

[英]Transform collective to array in Laravel, Laravel 5

How can I transform this collection to array and eject "whereNotIn" using a Laravel query, like this: 如何使用Laravel查询将该集合转换为数组并弹出“ whereNotIn”,如下所示:

->whereNotIn('id', ['collection'])->get();'


Collection {#259 ▼
#items: array:3 [▼
0 => {#257 ▼
  +"id": 2
}
1 => {#256 ▼
  +"id": 3
}
2 => {#237 ▼
  +"id": 6
}
]}

使用pluck(attribute)

->whereNotIn('id', $collection->pluck('id'))->get();

实际上,要获取数组,应将pluckall()方法一起使用,因此在这种情况下,应使用:

->whereNotIn('id', $collection->pluck('id')->all())->get();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM