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

theUnforgiven's avatar

but then that will insert as an array won't it which I dont want that to happen, need it to insert as many rows as possible based on the product id.

maximebeaudoin's avatar

@lstables Not sure to understand, currently, in your form, you display options already in database, i don't see anything related to insert a new option.

theUnforgiven's avatar

that's the question how would i insert multiple items in the options table based on whats input from the form.

maximebeaudoin's avatar

You can add special row at the end of you form used to add a new option row via javascript/ajax request. This way you will have the ID of the option use to update.

The only downside is your options will be add automaticly in your database before update but you could set the right value in the same time so, i don't think it's really a problem.

theUnforgiven's avatar

The only issue I have is the the values comes from the db to start with so if i was to change one value from size 6 to 10 for example that one change would need to be made in the db, so is Ajax the best way to achieve this?

maximebeaudoin's avatar

In fact, you have multiple options :

  1. You could create array input without ID {{ Form::select("size[]") }} and wipe every options on save, and create new one. If you chose this options, you could remove the ID table and configure your table schema to have unique value base on size, product_id, etc ..
  2. You could une array input with ID {{ Form::select("size[$id]") }} and update the value based on the id.

No matter which solution you choose, you need a way to add option in javascript, using ajax or not. To add a new row at the end of you form.

For the option 1, you could simply add the option in the DOM and catch the results after posting your form. Just remember to wipe old options before inserting new one.

For the option 2, you can add the value in the DOM via javascript, and create it in the same time in the database via Ajax request. This way, you will have the new options in your form with the old options using the $id as a key in your input. After that, you will be able to update old and new options.

Hope it's help !

theUnforgiven's avatar

So i need to learn ajax then as that seems to be the better option

Previous

Please or to participate in this conversation.