Skip to content

Commit 53c9619

Browse files
authored
Merge pull request #7 from spinen/feature/allowSettingAnArrayOfWheres
Allow for an array in the where
2 parents 36001cc + c868616 commit 53c9619

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/Support/Builder.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,21 @@ public function take(int|string $count): self
545545
*
546546
* @throws InvalidRelationshipException
547547
*/
548-
public function where(string $property, $value = true): self
548+
public function where(iterable|string $property, $value = true): self
549549
{
550-
$this->wheres[$property] = is_a($value, LaravelCollection::class)
551-
? $value->toArray()
552-
: $value;
550+
is_iterable($property)
551+
// Given multiple properties to set, so recursively call self
552+
? Collection::wrap($property)->each(
553+
fn ($v, string $p): self => is_numeric($p)
554+
// No value given, so use default value
555+
? $this->where($v, $value)
556+
// Pass property & value
557+
: $this->where($p, $v),
558+
)
559+
// Given single property
560+
: $this->wheres[$property] = is_a($value, LaravelCollection::class)
561+
? $value->toArray()
562+
: $value;
553563

554564
return $this;
555565
}

0 commit comments

Comments
 (0)