Skip to content

Commit

Permalink
Fix ErrorException in operatorForWhere collection method. (#20913)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieutu authored and taylorotwell committed Sep 1, 2017
1 parent d79f138 commit 7166315
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,18 +481,22 @@ protected function operatorForWhere($key, $operator, $value)
return function ($item) use ($key, $operator, $value) {
$retrieved = data_get($item, $key);

switch ($operator) {
default:
case '=':
case '==': return $retrieved == $value;
case '!=':
case '<>': return $retrieved != $value;
case '<': return $retrieved < $value;
case '>': return $retrieved > $value;
case '<=': return $retrieved <= $value;
case '>=': return $retrieved >= $value;
case '===': return $retrieved === $value;
case '!==': return $retrieved !== $value;
try {
switch ($operator) {
default:
case '=':
case '==': return $retrieved == $value;
case '!=':
case '<>': return $retrieved != $value;
case '<': return $retrieved < $value;
case '>': return $retrieved > $value;
case '<=': return $retrieved <= $value;
case '>=': return $retrieved >= $value;
case '===': return $retrieved === $value;
case '!==': return $retrieved !== $value;
}
} catch (Exception $e) {
return false;
}
};
}
Expand Down
13 changes: 13 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,19 @@ public function testWhere()
[['v' => 4]],
$c->where('v', '>', 3)->values()->all()
);

$object = (object) ['foo' => 'bar'];

$this->assertEquals(
[],
$c->where('v', $object)->values()->all()
);

$c = new Collection([['v' => 1], ['v' => $object]]);
$this->assertEquals(
[['v' => $object]],
$c->where('v', $object)->values()->all()
);
}

public function testWhereStrict()
Expand Down

0 comments on commit 7166315

Please sign in to comment.