我有以下查询
function foo(x,y){
return x,7;
}
foo(3,4);
它产生以下结果 -
$tag_query = UserTags::query();
$tag_query->whereIn('tag_id' , $insert_data['to_device']);
$tag_users = $tag_query->get(['user_id']);
我不想在结果数组中使用Array
(
[0] => Array
(
[_id] => 57da358e7ac6f6740e8b456a
[user_id] => 57d67290823fb647dd174739
)
[1] => Array
(
[_id] => 57da358e7ac6f6740e8b456c
[user_id] => 57d672cb823fb647dd17473a
)
[2] => Array
(
[_id] => 57da358e7ac6f6740e8b4571
[user_id] => 57d67549d81e1845e4dba983
)
)
,如何在不使用循环的情况下将其删除?
预期产出 -
_id
请帮忙!谢谢!
答案 0 :(得分:1)
您可以使用project()
方法将投影应用于您的查询:
$tag_query = UserTags::query();
$tag_query->whereIn('tag_id' , $insert_data['to_device']);
$tag_users = $tag_query->project(['_id' => 0, 'user_id' => 1])->get();