Skip to content
Advertisement

Laravel – Insert Selected Row

I have a table :

header 1 header 2 button
First row insert 
Second row insert
Third row insert

I want when the insert button is clicked, the row with that button is inserted in the database. So far I have in the controller :

JavaScript

And in blade :

JavaScript

But the last row is inserted whatever button is clicked..

Advertisement

Answer

You are not using an array so all your previous inputs will be replaced by the last one. If you don’t have any more fields to send with your request you can solve this by putting your form inside your loop. button tag also accepts a value so you can skip the hidden input field to use less code.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement