22
33namespace ProtoneMedia \Splade ;
44
5+ use Illuminate \Database \Eloquent \Model ;
56use Illuminate \Http \Request ;
67use Illuminate \Support \Arr ;
78
89class SpladeForm
910{
1011 protected ?AbstractForm $ configurator = null ;
1112
12- protected $ data = [];
13+ protected array | Model $ data = [];
1314
1415 protected array $ fields = [];
1516
@@ -51,7 +52,7 @@ public function setConfigurator(AbstractForm $configurator): self
5152 }
5253
5354 /**
54- * Sets the id for the form
55+ * Sets the id for the form.
5556 *
5657 * @return $this
5758 */
@@ -63,7 +64,7 @@ public function id(string $id = ''): self
6364 }
6465
6566 /**
66- * Sets the action for the form
67+ * Sets the action for the form.
6768 *
6869 * @return $this
6970 */
@@ -75,7 +76,7 @@ public function action(string $action = 'POST'): self
7576 }
7677
7778 /**
78- * Add css-class(es) to the form
79+ * Add css-class(es) to the form.
7980 *
8081 * @return $this
8182 */
@@ -112,7 +113,7 @@ public function confirm(
112113 }
113114
114115 /**
115- * Sets the values for the form fields
116+ * Sets the values for the form fields.
116117 *
117118 * @return $this
118119 */
@@ -124,7 +125,7 @@ public function fill($data): self
124125 }
125126
126127 /**
127- * Adds fields to the form
128+ * Adds fields to the form.
128129 *
129130 * @return $this
130131 */
@@ -136,7 +137,7 @@ public function fields(array $fields = []): self
136137 }
137138
138139 /**
139- * Prevent the page from scrolling to the top after submit
140+ * Prevent the page from scrolling to the top after submit.
140141 *
141142 * @param bool $stay
142143 * @return $this
@@ -149,9 +150,9 @@ public function preserveScroll(bool $preserve_scroll = true): self
149150 }
150151
151152 /**
152- * Require the user to confirm their password within the confirmation dialog
153+ * Require the user to confirm their password within the confirmation dialog.
153154 *
154- * Add `Route::spladePasswordConfirmation();` to your routes to make this work
155+ * Add `Route::spladePasswordConfirmation();` to your routes to make this work.
155156 *
156157 * @return $this
157158 */
@@ -175,7 +176,7 @@ public function requirePassword(
175176 }
176177
177178 /**
178- * Prevent navigation on submit
179+ * Prevent navigation on submit.
179180 *
180181 * @param string $actionOnSuccess reset|restore
181182 * @return $this
@@ -194,7 +195,7 @@ public function stay(bool $stay = true, string $actionOnSuccess = ''): self
194195 * Submit the form whenever a value changes.
195196 *
196197 * If one or morge fieldnames are provided in $watch_fields,
197- * the form will only be submitted on changes on these fields
198+ * the form will only be submitted on changes on these fields.
198199 *
199200 * @param array|string|null $watchFields
200201 * @return $this
@@ -213,7 +214,7 @@ public function submitOnChange(
213214 }
214215
215216 /**
216- * Set the method of the form
217+ * Set the method of the form.
217218 *
218219 * @return $this
219220 */
@@ -225,63 +226,63 @@ public function method(string $method = 'POST'): self
225226 }
226227
227228 /**
228- * Returns the id for the form
229+ * Returns the id for the form.
229230 */
230231 public function getId (): string
231232 {
232233 return $ this ->id ;
233234 }
234235
235236 /**
236- * Returns the action for the form
237+ * Returns the action for the form.
237238 */
238239 public function getAction (): string
239240 {
240241 return $ this ->action ;
241242 }
242243
243244 /**
244- * Returns the data for the form
245+ * Returns the data for the form.
245246 */
246247 public function getClass (): array |string
247248 {
248249 return $ this ->class ;
249250 }
250251
251252 /**
252- * Returns the data for the form
253+ * Returns the data for the form.
253254 */
254255 public function getData ()
255256 {
256257 return $ this ->data ;
257258 }
258259
259260 /**
260- * Returns all fields of the form
261+ * Returns all fields of the form.
261262 */
262263 public function getFields (): array
263264 {
264265 return $ this ->fields ;
265266 }
266267
267268 /**
268- * Returns the method for the form
269+ * Returns the method for the form.
269270 */
270271 public function getMethod (): string
271272 {
272273 return $ this ->method ;
273274 }
274275
275276 /**
276- * Return an option for the form arguments
277+ * Return an option for the form arguments.
277278 */
278279 public function getOption (string $ option ): array |bool |string |null
279280 {
280281 return $ this ->options [$ option ] ?? false ;
281282 }
282283
283284 /**
284- * Returns the forms rules
285+ * Returns the forms rules.
285286 */
286287 public function getRules (): array
287288 {
@@ -295,6 +296,7 @@ public function getRules(): array
295296 */
296297 public function validate (?Request $ request = null , ...$ params ): array
297298 {
299+ /** @var Request */
298300 $ request = $ request ?? request ();
299301
300302 return $ request ->validate ($ this ->getRules (), ...$ params );
0 commit comments