1 | <?php |
||
7 | class RouteKeyExists implements Rule |
||
8 | { |
||
9 | /** |
||
10 | * The model to validate. |
||
11 | * |
||
12 | * @var \Illuminate\Database\Eloquent\Model |
||
13 | */ |
||
14 | protected $model; |
||
15 | |||
16 | /** |
||
17 | * The attribute being validated. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $attribute; |
||
22 | |||
23 | /** |
||
24 | * Replace the route key in the request |
||
25 | * with the actual database value? |
||
26 | * |
||
27 | * @var string|bool |
||
28 | */ |
||
29 | protected $replaceAttribute = false; |
||
30 | |||
31 | /** |
||
32 | * Attribute with the actual database value |
||
33 | * to add to the request. |
||
34 | * |
||
35 | * @var string|bool |
||
36 | */ |
||
37 | protected $addAttribute = false; |
||
38 | |||
39 | /** |
||
40 | * Create a new rule instance. |
||
41 | * |
||
42 | * @param string $model |
||
43 | * |
||
44 | * @return static |
||
45 | */ |
||
46 | 4 | public static function model($model) |
|
50 | |||
51 | /** |
||
52 | * Create a new rule instance. |
||
53 | * |
||
54 | * @param string $model |
||
55 | */ |
||
56 | 4 | public function __construct($model) |
|
60 | |||
61 | /** |
||
62 | * Replace the route key in the request with the actual database value. |
||
63 | * If an attribute name is provided, the original request attribute |
||
64 | * name will be removed and replaced with the new one. |
||
65 | * |
||
66 | * @param string|null $attribute |
||
67 | * |
||
68 | * @return $this |
||
69 | */ |
||
70 | 2 | public function replace($attribute = null) |
|
76 | |||
77 | /** |
||
78 | * Add the given attribute with the actual |
||
79 | * database value to the request. |
||
80 | * |
||
81 | * @param string $attribute |
||
82 | * |
||
83 | * @return $this |
||
84 | */ |
||
85 | 1 | public function add($attribute) |
|
91 | |||
92 | /** |
||
93 | * Determine if the validation rule passes. |
||
94 | * |
||
95 | * @param string $attribute |
||
96 | * @param string $value |
||
97 | * |
||
98 | * @return bool |
||
99 | */ |
||
100 | 4 | public function passes($attribute, $value) |
|
112 | |||
113 | /** |
||
114 | * Get the validation error message. |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | 1 | public function message() |
|
124 | |||
125 | /** |
||
126 | * Update the request attributes if needed. |
||
127 | * |
||
128 | * @param \Illuminate\Database\Eloquent\Model $model |
||
129 | * |
||
130 | * @return void |
||
131 | */ |
||
132 | 4 | protected function updateRequest($model) |
|
149 | |||
150 | /** |
||
151 | * Merge the request attributes with the given key / value pair. |
||
152 | * |
||
153 | * @param string $key |
||
154 | * @param mixed $value |
||
155 | * |
||
156 | * @return void |
||
157 | */ |
||
158 | 3 | protected function mergeRequest($key, $value) |
|
164 | |||
165 | /** |
||
166 | * Remove an attribute from the request. |
||
167 | * |
||
168 | * @param mixed $attribute |
||
169 | * |
||
170 | * @return void |
||
171 | */ |
||
172 | 1 | protected function removeFromRequest($attribute) |
|
182 | } |
||
183 |