-
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.
[10.x] Add Collection::select() method (#49845)
* Add select method to Collection * style * Update Collection.php * Update LazyCollection.php --------- Co-authored-by: Craig Morris <> Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
8206d96
commit 4d4a760
Showing
4 changed files
with
107 additions
and
0 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
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 |
---|---|---|
|
@@ -4228,6 +4228,37 @@ public function testOnly($collection) | |
$this->assertEquals(['first' => 'Taylor', 'email' => '[email protected]'], $data->only(collect(['first', 'email']))->all()); | ||
} | ||
|
||
/** | ||
* @dataProvider collectionClassProvider | ||
*/ | ||
public function testSelect($collection) | ||
{ | ||
$data = new $collection([ | ||
['first' => 'Taylor', 'last' => 'Otwell', 'email' => '[email protected]'], | ||
['first' => 'Jess', 'last' => 'Archer', 'email' => '[email protected]'], | ||
]); | ||
|
||
$this->assertEquals($data->all(), $data->select(null)->all()); | ||
$this->assertEquals([['first' => 'Taylor'], ['first' => 'Jess']], $data->select(['first', 'missing'])->all()); | ||
$this->assertEquals([['first' => 'Taylor'], ['first' => 'Jess']], $data->select('first', 'missing')->all()); | ||
$this->assertEquals([['first' => 'Taylor'], ['first' => 'Jess']], $data->select(collect(['first', 'missing']))->all()); | ||
|
||
$this->assertEquals([ | ||
['first' => 'Taylor', 'email' => '[email protected]'], | ||
['first' => 'Jess', 'email' => '[email protected]'], | ||
], $data->select(['first', 'email'])->all()); | ||
|
||
$this->assertEquals([ | ||
['first' => 'Taylor', 'email' => '[email protected]'], | ||
['first' => 'Jess', 'email' => '[email protected]'], | ||
], $data->select('first', 'email')->all()); | ||
|
||
$this->assertEquals([ | ||
['first' => 'Taylor', 'email' => '[email protected]'], | ||
['first' => 'Jess', 'email' => '[email protected]'], | ||
], $data->select(collect(['first', 'email']))->all()); | ||
} | ||
|
||
/** | ||
* @dataProvider collectionClassProvider | ||
*/ | ||
|