Skip to content

Commit 6a2dff3

Browse files
authored
Update DatabaseRule to handle Enums for simple where clause (#47679)
1 parent b83abb4 commit 6a2dff3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Illuminate/Validation/Rules/DatabaseRule.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Validation\Rules;
44

5+
use BackedEnum;
56
use Closure;
67
use Illuminate\Contracts\Support\Arrayable;
78
use Illuminate\Database\Eloquent\Model;
@@ -81,7 +82,7 @@ public function resolveTableName($table)
8182
* Set a "where" constraint on the query.
8283
*
8384
* @param \Closure|string $column
84-
* @param \Illuminate\Contracts\Support\Arrayable|array|string|int|bool|null $value
85+
* @param \Illuminate\Contracts\Support\Arrayable|\BackedEnum|\Closure|array|string|int|bool|null $value
8586
* @return $this
8687
*/
8788
public function where($column, $value = null)
@@ -98,6 +99,10 @@ public function where($column, $value = null)
9899
return $this->whereNull($column);
99100
}
100101

102+
if ($value instanceof BackedEnum) {
103+
$value = $value->value;
104+
}
105+
101106
$this->wheres[] = compact('column', 'value');
102107

103108
return $this;
@@ -107,7 +112,7 @@ public function where($column, $value = null)
107112
* Set a "where not" constraint on the query.
108113
*
109114
* @param string $column
110-
* @param \Illuminate\Contracts\Support\Arrayable|array|string $value
115+
* @param \Illuminate\Contracts\Support\Arrayable|\BackedEnum|array|string $value
111116
* @return $this
112117
*/
113118
public function whereNot($column, $value)
@@ -116,6 +121,10 @@ public function whereNot($column, $value)
116121
return $this->whereNotIn($column, $value);
117122
}
118123

124+
if ($value instanceof BackedEnum) {
125+
$value = $value->value;
126+
}
127+
119128
return $this->where($column, '!'.$value);
120129
}
121130

0 commit comments

Comments
 (0)