-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow column aliases in query builder pluck
- Loading branch information
1 parent
597a0af
commit 4fd6db1
Showing
2 changed files
with
8 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' => '[email protected]']); | ||
$user2 = EloquentTestUser::create(['id' => 2, 'email' => '[email protected]']); | ||
$user1 = EloquentTestUser::create(['id' => 1, 'name' => 'Taylor', 'email' => '[email protected]']); | ||
$user2 = EloquentTestUser::create(['id' => 2, 'name' => 'Abigail', 'email' => '[email protected]']); | ||
|
||
$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() | ||
|