Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MeisamTj's avatar

v-model two dimensional array

Hi there, I'm developing an e-commerce app. In create new product I add a button to add product variations details. In regular form usually it would be name property something like

  • name = "variation[quantity][]"
  • name = "variation[price][]"

Then in laravel as backend it would receive a two dimensional array. But with v-model I couldn't find a way to use array. How can I make it work? I use inertia.js and useForm by the way. Thanks in forward.

0 likes
2 replies
martinbean's avatar

@meisamtj I’m pretty sure v-model works with “complex” values such as arrays and objects as well.

You’ll need to keep your variations in a variable in your “parent” component, and you can then pass it to some child component as a v-model value:

<variations-input v-model="variations" />

Your variations-input should then emit a update:modelValue event with the new variations object when you add/edit/remove a variation.

1 like
MeisamTj's avatar

@martinbean Thanks for your response. I made a method to push an object when adding new variation. It solved the issue. I have another issue with validation.

Validate response sends variation.0.value in error message I use variatin.index.value but it can't be read and throw an error something like there is no such this thing.

I used variation.${index}.value with back tick but it sends the phrase as message in inertia InputError component. Validation variation.*.value get complicated as well. I think I should pass index to input error component somehow!

Please or to participate in this conversation.