
Four Ways to Trigger Delete Row from a Table
Assume we have this route: Route::delete('/pages/{page}', [PageController::class, 'destroy'] )->name('site.pages.destroy'); Every delete must: Open confirmation modal Wait for user confirmation Then trigger DELETE request We are only discussing how the front end triggers the route. 1. One Form Per Row Each row contains its own form. Blade @foreach ($pages as $page) <tr> <td>{{ $page->title }}</td> <td> <form id="delete-form-{{ $page->id }}" action="{{ route('site.pages.destroy', $page->id) }}" method="POST"> @csrf @method('DELETE') <button type="button" onclick="openModal({{ $page->id }})"> Delete </button> </form> </td> </tr> @endforeach JavaScript <script> let selectedId = null; function openModal(id) { selectedId = id; document.getElementById('delete-user-modal').classList.remove('hidden'); } function submitDelete() { document .getElementById('delete-form-' + selectedId) .submit(); } </script> What’s Happening Each row has its own form Modal opens On confirmation → that specific for
Continue reading on Dev.to Tutorial
Opens in a new tab

