In the Laravel Docs on validation they speak of 'nested parameters':
If your HTTP request contains "nested" parameters, you may specify them in your validation rules using "dot" syntax:
$this->validate($request, [ 'title' => 'required|unique:posts|max:255', 'author.name' => 'required', 'author.description' => 'required', ]);
What would the HTML look like for this nesting? I googled around, and found nothing except things about form nesting. Also, the "dot" syntax
, is this specific to Laravel?
The dot notation is for easily accessing array elements, and making their selectors more "fluent".
Validating author.name
would be the equivalent of having checking the value of the input <input type="text" name="author[name]" />
.
This makes having multi model forms or grouping related data much nicer =). You can then get all the data for that thing by doing something like $request->request('author');
and that would give you the collection/array of all the values submitted with author[*]
. Laravel also uses it with its config accessors - so config.setting.parameter
is the equivalent of config[setting][parameter]
Basically makes working with array data easier.
See https://github.com/glopezdetorre/dot-notation-access for some examples!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With