Laravel 如何使用foreach Elount获取数据
我有一个问题,以获取数据使用forach雄辩在拉威尔6 获取我希望在foreach中使用的值Laravel 如何使用foreach Elount获取数据,laravel,foreach,eloquent,Laravel,Foreach,Eloquent,我有一个问题,以获取数据使用forach雄辩在拉威尔6 获取我希望在foreach中使用的值 $array_suspect_idBLE = Transaction:: select('id_ble') ->where('id_user',$suspect_id) ->where('updated_at','>=',$suspect_in) ->where('up
$array_suspect_idBLE = Transaction::
select('id_ble')
->where('id_user',$suspect_id)
->where('updated_at','>=',$suspect_in)
->where('updated_at','<=',$suspect_out)
->pluck('id_ble');
和foreach
foreach($array_suspect_idBLE as $arr){
$suspect_list = Transaction::
select('id_transaction','id_user','id_ble')
->where('id_user','<>',$suspect_id)
->where('updated_at','>=',$suspect_in)
->where('updated_at','<=',$suspect_out)
->where('id_ble', $arr->array_suspect_idBLE)
->get();
}
foreach($array\u suspect\u idBLE as$arr){
$suspect_list=交易记录:
选择('id\u事务'、'id\u用户'、'id\u表')
->其中('id\u user',''$suspect\u id)
->其中('updated_at','>=',$suspect_in)
->其中('updated_at','问题在于pluck()
方法返回一个值数组。您将其视为返回一个对象集合
解决方案是将其改为:
foreach($array\u suspect\u idBLE as$value){
$suspect_list=交易记录:
选择('id\u事务'、'id\u用户'、'id\u表')
->其中('id\u user',''$suspect\u id)
->其中('updated_at','>=',$suspect_in)
->在哪里('updated_at','you don't object you have when ever value in the field on the table如果你点击该列,结果你有一个ID列表。在你的可疑列表查询中,只需使用$arr
而不是$arr->array\u suspect\u idBLE
。谢谢你的回答。结果是正确的,但没有显示所有数据。我想是因为每次迭代的替换。数据只显示连接到数组的连接。\u suspect\u idBLE=10。第一个数组如18,6,12,16如何
foreach($array_suspect_idBLE as $arr){
$suspect_list = Transaction::
select('id_transaction','id_user','id_ble')
->where('id_user','<>',$suspect_id)
->where('updated_at','>=',$suspect_in)
->where('updated_at','<=',$suspect_out)
->where('id_ble', $arr->array_suspect_idBLE)
->get();
}