Skip to content

Commit

Permalink
add support for not
Browse files Browse the repository at this point in the history
  • Loading branch information
esbenp committed Aug 27, 2019
1 parent 48bfd97 commit 544d2f8
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,35 @@ protected function getCreatedAtColumn()
return ($model::CREATED_AT) ? $model::CREATED_AT : 'created_at';
}

protected function applyWhereArray($query, array $clauses)
protected function applyWhereArray(Builder $query, array $clauses)
{
foreach ($clauses as $key => $value) {
preg_match('/NOT\:(.+)/', $key, $matches);

$not = false;
if (isset($matches[1])) {
$not = true;
$key = $matches[1];
}

if (is_array($value)) {
$query->whereIn($key, $value);
if (!$not) {
$query->whereIn($key, $value);
} else {
$query->whereNotIn($key, $value);
}
} else if (is_null($value)) {
$query->whereNull($key);
if (!$not) {
$query->whereNull($key);
} else {
$query->whereNotNull($key);
}
} else {
$query->where($key, $value);
if (!$not) {
$query->where($key, $value);
} else {
$query->whereNot($key, $value);
}
}
}
}
Expand Down

0 comments on commit 544d2f8

Please sign in to comment.