Skip to content

Commit

Permalink
Allow for an array in the where
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmypuckett committed Dec 10, 2023
1 parent 36001cc commit c868616
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Support/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,21 @@ public function take(int|string $count): self
*
* @throws InvalidRelationshipException
*/
public function where(string $property, $value = true): self
public function where(iterable|string $property, $value = true): self
{
$this->wheres[$property] = is_a($value, LaravelCollection::class)
? $value->toArray()
: $value;
is_iterable($property)
// Given multiple properties to set, so recursively call self
? Collection::wrap($property)->each(
fn ($v, string $p): self => is_numeric($p)
// No value given, so use default value
? $this->where($v, $value)
// Pass property & value
: $this->where($p, $v),
)
// Given single property
: $this->wheres[$property] = is_a($value, LaravelCollection::class)
? $value->toArray()
: $value;

return $this;
}
Expand Down

0 comments on commit c868616

Please sign in to comment.