In Laravel using Route::resource, the method should be "DELETE" instead of "GET" to delete a row/record so I have to use Form
like this.
<form action="{{ route('category.destroy', $category->id]) }}" method="POST">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger btn-block">Delete</button>
</form>
it is working fine but I want to confirm before deleting.
I can show bootstrap model for confirmation but am unable to pass and use the $category->id in the model.
is there any better way.
2
Answers
Finally, I've done it like this. I used
<a>
tag to show delete confirmation model and passedroute
andcategory->id
tohref
.included the
from
in the bootstrap model withaction = ""
then in jQuery I get the value of
href
of clicked<a>
tage and passed it toaction
attribute of theform
in the bootstrap model.and this is the complete solution.
You can user bootstrap modal but i suggest you sweet alert its easy and perfect . You will see a confirmation message before you delete the record and if you want delete record using bootstrap modal use this above form inside modal like image i have sent.enter image description here
Good Luck!