Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Allow to automatically use where/whereIn or whereNot/whereNotIn methods in DatabaseRule #20739

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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