Reputation: 5344
I have following query
$tag_query = UserTags::query();
$tag_query->whereIn('tag_id' , $insert_data['to_device']);
$tag_users = $tag_query->get(['user_id']);
it is generating following result -
Array
(
[0] => Array
(
[_id] => 57da358e7ac6f6740e8b456a
[user_id] => 57d67290823fb647dd174739
)
[1] => Array
(
[_id] => 57da358e7ac6f6740e8b456c
[user_id] => 57d672cb823fb647dd17473a
)
[2] => Array
(
[_id] => 57da358e7ac6f6740e8b4571
[user_id] => 57d67549d81e1845e4dba983
)
)
I don't want _id
in result array , how can I remove it without using loop?
expected output -
Array
(
[0] => Array
(
[user_id] => 57d67290823fb647dd174739
)
[1] => Array
(
[user_id] => 57d672cb823fb647dd17473a
)
[2] => Array
(
[user_id] => 57d67549d81e1845e4dba983
)
)
please help! Thanks!
Upvotes: 2
Views: 401
Reputation: 103475
You can apply projections to your queries using the project()
method:
$tag_query = UserTags::query();
$tag_query->whereIn('tag_id' , $insert_data['to_device']);
$tag_users = $tag_query->project(['_id' => 0, 'user_id' => 1])->get();
Upvotes: 1