Skip to content

Commit 7b20796

Browse files
authored
Merge pull request #27 from Weebly/wherein-subquery
Wherein subquery
2 parents 8b8f756 + fd26756 commit 7b20796

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
"keywords": ["laravel", "eloquent", "uuid", "encrypt", "database"],
77
"require": {
88
"ramsey/uuid": "~3.0",
9-
"illuminate/database": "~6.0",
10-
"illuminate/support": "~6.0",
11-
"illuminate/encryption": "~6.0"
9+
"illuminate/database": ">=5.0 <7.0.0",
10+
"illuminate/support": ">=5.0 <7.0.0",
11+
"illuminate/encryption": ">=5.0 <7.0.0"
1212
},
1313
"require-dev": {
1414
"mockery/mockery": "^1.0",
1515
"phpunit/phpunit": "^8.0",
1616
"laravel/framework": "6.*",
17-
"orchestra/testbench": "~4.0"
17+
"orchestra/testbench": ">=3.0 <5.0.0"
1818
},
1919
"autoload": {
2020
"psr-4": {

src/Database/EloquentBuilder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ public function whereIn($column, $values, $boolean = 'and', $not = false)
9999
// Loop over all values and mutate them
100100
$mutatedValues = [];
101101
foreach ($where['values'] as $value) {
102-
$mutatedValues[] = $this->model->serializeAttribute($mutatedColumn, $value);
102+
if ($value instanceof Expression) {
103+
$mutatedValues[] = $value;
104+
} else {
105+
$mutatedValues[] = $this->model->serializeAttribute($mutatedColumn, $value);
106+
}
103107
}
104108

105109
// Modify the values

tests/Integration/MutatorTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ public function test_where_in()
118118
$this->assertEquals(2, $p->count());
119119
}
120120

121+
public function test_where_in_subquery()
122+
{
123+
$id = Uuid::uuid1()->toString();
124+
$id2 = Uuid::uuid1()->toString();
125+
(new TestModel())->create(['id' => $id, 'name' => 'A chair']);
126+
(new TestModel())->create(['id' => $id2, 'name' => 'A table']);
127+
$p = TestModel::whereIn('id', function ($query) {
128+
$query->select('id')->from('test_model');
129+
})->get();
130+
$this->assertEquals(2, $p->count());
131+
$this->assertEquals($id, $p->first()->id);
132+
$this->assertEquals($id2, $p->last()->id);
133+
}
134+
121135
public function test_where_not_in()
122136
{
123137
$id = Uuid::uuid1()->toString();

0 commit comments

Comments
 (0)