|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Larapie\Actions\Attributes\Rules; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Validation\Rule; |
|
8
|
|
|
use Larapie\Actions\Attribute; |
|
9
|
|
|
|
|
10
|
|
|
trait GeneralRules |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @return static |
|
14
|
|
|
*/ |
|
15
|
1 |
|
public function nullable() |
|
16
|
|
|
{ |
|
17
|
1 |
|
return $this->rule('nullable'); |
|
|
|
|
|
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param \Closure|bool $callback |
|
22
|
|
|
* @return GeneralRules |
|
23
|
|
|
*/ |
|
24
|
|
|
public function requireIf($callback) |
|
25
|
|
|
{ |
|
26
|
|
|
if (is_callable($callback)) { |
|
27
|
|
|
return call_user_func($callback) ? $this->require() : $this; |
|
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
return $callback ? $this->require() : $this; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function requiredIfField(string $field, ...$values) |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->rule("required_if:$field, " . implode(',', $values)); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function requiredUnlessField(string $field, ...$values) |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->rule("required_unless:$field," . implode(',', $values)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
public function requiredWith(string ...$fields) |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->rule("required_with:" . implode(',', $fields)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function requiredWithAll(string ...$fields) |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->rule("required_with_all:" . implode(',', $fields)); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function requiredWithout(string ...$fields) |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->rule("required_without:" . implode(',', $fields)); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function requiredWithoutAll(string ...$fields) |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->rule("required_without_all:" . implode(',', $fields)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function distinct() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->rule('distinct'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function same(string $field) |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->rule("same:$field"); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function excludeIf(string $field, $value) |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->rule("exclude_if:$field,$value"); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function excludeUnless(string $field, $value) |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->rule("exclude_unless:$field,$value"); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function exists(string $table, string $column) |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->rule("exists:$table,$column"); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function filled() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->rule('filled'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function present() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->rule('present'); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function url() |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->rule('url'); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function uuid() |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->rule('uuid'); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function unique(string $tableOrModel, string $column) |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->rule("unique:$tableOrModel,$column"); |
|
112
|
|
|
} |
|
113
|
|
|
} |