File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
src/Illuminate/Validation/Rules Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -34,14 +34,14 @@ public function __construct($type)
34
34
*/
35
35
public function passes ($ attribute , $ value )
36
36
{
37
- if (is_null ($ value ) || ! function_exists ('enum_exists ' ) || ! enum_exists ($ this ->type ) || ! method_exists ($ this ->type , 'tryFrom ' )) {
38
- return false ;
39
- }
40
-
41
37
if ($ value instanceof $ this ->type ) {
42
38
return true ;
43
39
}
44
40
41
+ if (is_null ($ value ) || ! function_exists ('enum_exists ' ) || ! enum_exists ($ this ->type ) || ! method_exists ($ this ->type , 'tryFrom ' )) {
42
+ return false ;
43
+ }
44
+
45
45
try {
46
46
return ! is_null ($ this ->type ::tryFrom ($ value ));
47
47
} catch (TypeError $ e ) {
Original file line number Diff line number Diff line change @@ -52,6 +52,21 @@ public function testvalidationPassesWhenPassingInstanceOfEnum()
52
52
$ this ->assertFalse ($ v ->fails ());
53
53
}
54
54
55
+ public function testvalidationPassesWhenPassingInstanceOfPureEnum ()
56
+ {
57
+ $ v = new Validator (
58
+ resolve ('translator ' ),
59
+ [
60
+ 'status ' => PureEnum::one,
61
+ ],
62
+ [
63
+ 'status ' => new Enum (PureEnum::class),
64
+ ]
65
+ );
66
+
67
+ $ this ->assertFalse ($ v ->fails ());
68
+ }
69
+
55
70
public function testValidationFailsWhenProvidingNoExistingCases ()
56
71
{
57
72
$ v = new Validator (
You can’t perform that action at this time.
0 commit comments