Skip to content
Advertisement

Laravel: Delete data with wrong ID

I use the Delete button to delete data, but when deleting data, the deleted data does not match the rows I mean, but the data that is deleted is the data that is at the top of the table

when I use return $meja, it should appear id 7 but id 1 instead

For further details :

view :

JavaScript

here is my javascript

JavaScript

Here is my controller :

JavaScript

Here is my Router :

JavaScript

Advertisement

Answer

it is because of id confliction. your every form id is delete but in a dom there should be a single element with an id. when you are using sweet alert to submit the delete form, the very first form with delete id got submitted, hence the first item got deleted. use unique id or class instead. an example for you using class

form

JavaScript

sweet alert code

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