Getting the correct ID to delete in site with multiple posts
Solution 1:
This is your form :
<form method="post" action="{{ route('delete', $bewerbung->Bewerbung_ID)}}">
but it's in a loop, so presumably you are creating lots of them, each with the same button with the same ID :
<button type="submit" id="ok_btn" ... >
Since ID has to be unique, when your javascript fires, it looks for the element with ID "ok_btn" to submit the relevant form. Since there are lots (again, ID should be unique) then it just submits the first one it comes to. So it will always just delete the first one on the page.
My suggestion would be :
- Don't put the form or the modal in the loop.
- Put the modal at the end, with the form inside it, and within the form have a hidden field (called, say, "delete_id".
- Use javascript to populate the "delete_id" with the relevant ID of the thing to be deleted when the user clicks to bring up the modal.
- Use the confirmation button to submit the form, as you do at the moment.