[Estoy haciendo un CRUD con Laravel 7 en tabla y lo que quiero es que cuando presiono elbotónde eliminar en un producto la tabla,me aparezca un modal de Bootstrap para Confirmar si quiero eliminarlo。错误消除了模态多边校正,并确认了错误:此路线不支持DELETE方法。支持的方法:GET,HEAD,POST。
Ruta:
Route::resource('products', 'ProductsController');
ProductsController:
public function destroy($id)
{
Product::destroy($id);
return redirect("/products");
}
Llamado a modal dentro de tabla:
<td>
<a href="javascript:void(0)" class="btn btn-danger deleteBtn" data-toggle="modal" data-target="#deleteModalpop"><span class="icon-bin"></a>
</td>
Modal:
<div class="modal fade" id="deleteModalpop" tabindex="-1" role="dialog" aria-labelledby="deleteModalpopLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModalpopLabel">Eliminar producto</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="" id="delete_modal" method="POST">
@method('DELETE')
@csrf
<div class="modal-body">
<input type="text" id="delete_product_id">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancelar</button>
<button type="submit" class="btn btn-danger">Eliminar</button>
</div>
</form>
</div>
</div>
</div>
Javascript:
$('#example').on('click','.deleteBtn',function() {
$tr = $(this).closest('tr');
var data = $tr.children("td").map(function(){
return $(this).text();
}).get();
// console.log(data);
$('#delete_product_id').val(data[0]);
$('delete_modal').attr('action' , '/products/'+data[0]);
$('deleteModalpop').modal('show');
});
#
。$('#delete_modal').attr('action' , '/products/' + data[0]);