diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index dd762d1dda88..105cf44807fc 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -3384,7 +3384,7 @@ public function pluck($column, $key = null) // given columns / key. Once we have the results, we will be able to take // the results and get the exact data that was requested for the query. $queryResult = $this->onceWithColumns( - is_null($key) ? [$column] : [$column, $key], + is_null($key) || $key === $column ? [$column] : [$column, $key], function () { return $this->processor->processSelect( $this, $this->runSelect() diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index a8caf61f6016..97f127f9074a 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -3364,6 +3364,17 @@ public function testPluckMethodGetsCollectionOfColumnValues() $this->assertEquals([1 => 'bar', 10 => 'baz'], $results->all()); } + public function testPluckAvoidsDuplicateColumnSelection() + { + $builder = $this->getBuilder(); + $builder->getConnection()->shouldReceive('select')->once()->with('select "foo" from "users" where "id" = ?', [1], true)->andReturn([['foo' => 'bar']]); + $builder->getProcessor()->shouldReceive('processSelect')->once()->with($builder, [['foo' => 'bar']])->andReturnUsing(function ($query, $results) { + return $results; + }); + $results = $builder->from('users')->where('id', '=', 1)->pluck('foo', 'foo'); + $this->assertEquals(['bar' => 'bar'], $results->all()); + } + public function testImplode() { // Test without glue.