Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are nested parameters in http?

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?

like image 773
KJdev Avatar asked Jun 24 '16 15:06

KJdev


1 Answers

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!

like image 172
OnIIcE Avatar answered Sep 28 '22 08:09

OnIIcE