File tree Expand file tree Collapse file tree 2 files changed +16
-21
lines changed
src/Illuminate/Validation Expand file tree Collapse file tree 2 files changed +16
-21
lines changed Original file line number Diff line number Diff line change @@ -63,25 +63,25 @@ public static function notIn($values)
63
63
}
64
64
65
65
/**
66
- * Get a unique constraint builder instance.
66
+ * Get a required_if constraint builder instance.
67
67
*
68
- * @param string $table
69
- * @param string $column
70
- * @return \Illuminate\Validation\Rules\Unique
68
+ * @param callable $callback
69
+ * @return \Illuminate\Validation\Rules\RequiredIf
71
70
*/
72
- public static function unique ( $ table , $ column = ' NULL ' )
71
+ public static function requiredIf ( $ callback )
73
72
{
74
- return new Rules \Unique ( $ table , $ column );
73
+ return new Rules \RequiredIf ( $ callback );
75
74
}
76
75
77
76
/**
78
- * Get a required_if constraint builder instance.
77
+ * Get a unique constraint builder instance.
79
78
*
80
- * @param \Closure $callback
81
- * @return \Illuminate\Validation\Rules\RequiredIf
79
+ * @param string $table
80
+ * @param string $column
81
+ * @return \Illuminate\Validation\Rules\Unique
82
82
*/
83
- public static function requiredIf ( $ callback )
83
+ public static function unique ( $ table , $ column = ' NULL ' )
84
84
{
85
- return new Rules \RequiredIf ( $ callback );
85
+ return new Rules \Unique ( $ table , $ column );
86
86
}
87
87
}
Original file line number Diff line number Diff line change 6
6
7
7
class RequiredIf
8
8
{
9
- /**
10
- * The name of the rule.
11
- */
12
- protected $ rule = 'required ' ;
13
-
14
9
/**
15
10
* The condition that validates the attribute.
16
11
*
17
- * @var bool|\Closure
12
+ * @var callable|bool
18
13
*/
19
14
public $ condition ;
20
15
21
16
/**
22
17
* Create a new required validation rule based on a condition.
23
18
*
24
- * @param bool|\Closure $condition
19
+ * @param callable|bool $condition
25
20
* @return void
26
21
*/
27
22
public function __construct ($ condition )
@@ -36,10 +31,10 @@ public function __construct($condition)
36
31
*/
37
32
public function __toString ()
38
33
{
39
- if ($ this ->condition instanceof Closure ) {
40
- return $ this ->condition -> __invoke ( ) ? $ this -> rule : '' ;
34
+ if (is_callable ( $ this ->condition ) ) {
35
+ return call_user_func ( $ this ->condition ) ? ' required ' : '' ;
41
36
}
42
37
43
- return $ this ->condition ? $ this -> rule : '' ;
38
+ return $ this ->condition ? ' required ' : '' ;
44
39
}
45
40
}
You can’t perform that action at this time.
0 commit comments