diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 7293ea045fbd..bb3ceb55ae29 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -1562,14 +1562,14 @@ public function lists($column, $key = null) } /** - * Strip off the table name from a column identifier. + * Strip off the table name or alias from a column identifier. * * @param string $column * @return string */ protected function stripTable($column) { - return is_null($column) ? $column : last(explode('.', $column)); + return is_null($column) ? $column : last(preg_split('~\.| ~', $column)); } /** diff --git a/tests/Database/DatabaseEloquentIntegrationTest.php b/tests/Database/DatabaseEloquentIntegrationTest.php index 80de3709ba05..11ce324a4274 100644 --- a/tests/Database/DatabaseEloquentIntegrationTest.php +++ b/tests/Database/DatabaseEloquentIntegrationTest.php @@ -41,6 +41,7 @@ public function setUp() { $this->schema()->create('users', function ($table) { $table->increments('id'); + $table->string('name')->nullable(); $table->string('email')->unique(); $table->string('role')->default('standard'); $table->timestamps(); @@ -181,16 +182,17 @@ public function testPluck() public function testPluckWithJoin() { - $user1 = EloquentTestUser::create(['id' => 1, 'email' => 'taylorotwell@gmail.com']); - $user2 = EloquentTestUser::create(['id' => 2, 'email' => 'abigailotwell@gmail.com']); + $user1 = EloquentTestUser::create(['id' => 1, 'name' => 'Taylor', 'email' => 'taylorotwell@gmail.com']); + $user2 = EloquentTestUser::create(['id' => 2, 'name' => 'Abigail', 'email' => 'abigailotwell@gmail.com']); $user2->posts()->create(['id' => 1, 'name' => 'First post']); $user1->posts()->create(['id' => 2, 'name' => 'Second post']); $query = EloquentTestUser::join('posts', 'users.id', '=', 'posts.user_id'); - $this->assertEquals([1 => 'First post', 2 => 'Second post'], $query->pluck('name', 'posts.id')->all()); - $this->assertEquals([2 => 'First post', 1 => 'Second post'], $query->pluck('name', 'users.id')->all()); + $this->assertEquals([1 => 'First post', 2 => 'Second post'], $query->pluck('posts.name', 'posts.id')->all()); + $this->assertEquals([2 => 'First post', 1 => 'Second post'], $query->pluck('posts.name', 'users.id')->all()); + $this->assertEquals(['Abigail' => 'First post', 'Taylor' => 'Second post'], $query->pluck('posts.name', 'users.name as user_name')->all()); } public function testFindOrFail()