diff --git a/src/Query/Builder.php b/src/Query/Builder.php index 372dcf633..eeb5ffe8d 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -851,15 +851,6 @@ public function pluck($column, $key = null) { $results = $this->get($key === null ? [$column] : [$column, $key]); - // Convert ObjectID's to strings - if (((string) $key) === '_id') { - $results = $results->map(function ($item) { - $item['_id'] = (string) $item['_id']; - - return $item; - }); - } - $p = Arr::pluck($results, $column, $key); return new Collection($p); diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 523ad3411..136b1cf72 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -525,6 +525,17 @@ public function testPluck() $this->assertEquals([25], $age); } + public function testPluckObjectId() + { + $id = new ObjectId(); + DB::table('users')->insert([ + ['id' => $id, 'name' => 'Jane Doe'], + ]); + + $names = DB::table('users')->pluck('name', 'id')->toArray(); + $this->assertEquals([(string) $id => 'Jane Doe'], $names); + } + public function testList() { DB::table('items')->insert([