我在laravel 6中使用forach eloquent获取数据时遇到了问题。
来获取我想在foreach中使用的值
$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');输出
Illuminate\Support\Collection {#281
#items: array:5 [
0 => 18
1 => 6
2 => 12
3 => 16
4 => 10
]
}和森林
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();
}错误是
消息:正在尝试获取非对象的属性'array_suspect_idBLE‘
预期结果是连接到array_suspect_idBLE 18、6、12、16、10所有id_transaction、id_user、id_ble
任何帮助都将不胜感激。
谢谢
发布于 2020-09-10 21:08:21
问题是pluck()方法返回一个值数组。您可以将其视为返回一个对象集合。
解决方案是将其更改为以下内容:
foreach($array_suspect_idBLE as $value) {
$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', $value)
->get();
}https://stackoverflow.com/questions/63830325
复制相似问题