Howdy_McGee
1 month ago
239
3
Tips

Arrays in Form Names - Good or Bad Practice?

Posted 1 month ago by Howdy_McGee

I'm working with a form where multiple components are brought together, A Person and a List. In the form I'm separating these by array:

Some issues I've run into:

I've tried working with @errors but it accepts only dot notation. I didn't find any helpers for converting person[name] to dot notation so I had to write my own. In the validation the required validate outputs the entire dot notation person.name is required which doesn't necessarily work in ever case. I didn't see an easy way to "filter" this validate message without creating my own custom validation.

I'm new to Laravel so I guess my question is, how common is the naming convention above for my inputs? Is this something I should avoid or are there helper functions I'm not familiar with to aid me in this process?

:: Edits ::

This is really just theory. If I have multiple Model fields in a form, is it a better practice to prefix them with the model or group them in an array? post_xyz vs post[xyz].

Some examples:

A post form might have a post title, post body, and categories. Products might have available stores.

Please sign in or create an account to participate in this conversation.