Skip to content

Commit

Permalink
Allow to automatically use where/whereIn or whereNot/whereNotIn methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mnabialek committed Aug 24, 2017
1 parent 33c56ab commit 4df8f8d
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/Illuminate/Validation/Rules/DatabaseRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ public function __construct($table, $column = 'NULL')
* Set a "where" constraint on the query.
*
* @param string $column
* @param string $value
* @param string|array $value
* @return $this
*/
public function where($column, $value = null)
{
if (is_array($value)) {
return $this->whereIn($column, $value);
}

if ($column instanceof Closure) {
return $this->using($column);
}
Expand All @@ -69,11 +73,15 @@ public function where($column, $value = null)
* Set a "where not" constraint on the query.
*
* @param string $column
* @param string $value
* @param string|array $value
* @return $this
*/
public function whereNot($column, $value)
{
if (is_array($value)) {
return $this->whereNotIn($column, $value);
}

return $this->where($column, '!'.$value);
}

Expand Down Expand Up @@ -103,11 +111,15 @@ public function whereNotNull($column)
* Set a "where in" constraint on the query.
*
* @param string $column
* @param array $values
* @param string|array $values
* @return $this
*/
public function whereIn($column, array $values)
public function whereIn($column, $values)
{
if (! is_array($values)) {
return $this->where($column, $values);
}

return $this->where(function ($query) use ($column, $values) {
$query->whereIn($column, $values);
});
Expand All @@ -117,11 +129,15 @@ public function whereIn($column, array $values)
* Set a "where not in" constraint on the query.
*
* @param string $column
* @param array $values
* @param string|array $values
* @return $this
*/
public function whereNotIn($column, array $values)
public function whereNotIn($column, $values)
{
if (! is_array($values)) {
return $this->whereNot($column, $values);
}

return $this->where(function ($query) use ($column, $values) {
$query->whereNotIn($column, $values);
});
Expand Down

0 comments on commit 4df8f8d

Please sign in to comment.