Laravel 中的 bootstrap 模态内的删除按钮不起作用
Delete button is not working inside of bootstrap modal in Laravel
我在 Laravel 中创建了分页,我还创建了删除按钮,允许我删除记录,这些记录效果很好。我的下一步是用 bootstrap 模式升级删除按钮。 bootstrap 模态单独工作正常,无需在模态主体内放置任何代码。在我将粘贴的删除代码复制到模态主体内后,出现错误:
Route [/admin/resellers/{{ $reseller->id ] not defined. (View:
但我不明白的是,此路由代码在 Laravel 代码中工作正常,但在 bootstrap 模态代码中不起作用,因为两者是相同的代码!为什么!我花了一个小时想弄清楚,任何想法!
在添加到 bootstrap 代码之前,如果工作正常 Laravel(没有 bootstrap 模态)。
<td class="center">
<form action="/admin/resellers/{{ $reseller->id }}" method="POST">
<strong><a href="/admin/resellers/{{ $reseller->id }}" class="btn btn-primary btn-sm btn-mini" >
<i class="fas fa-pen fa-fw"></i>View</a></strong>
@method('DELETE')
@csrf
<button class="btn btn-secondary btn-sm btn-mini"><i class="far fa-edit fa-fw"></i>Edit
<button class="btn btn-danger btn-sm btn-mini" ><i class="fas fa-times fa-fw"></i>Delete</button>
</form>
按钮触发模式
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#deletes">
<i class="fas fa-times fa-fw"></i>Delete</button>
在路由器中
Route::delete('/admin/resellers/{reseller}','ResellerController@destory');
内部 bootstrap 模态相同删除编码
<!-- Delete Modal -->
<div class="modal modal-danger fade" id="deletes" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title text-center" id="exampleModalLabel"><h4 class="modal-title">Delete Confirmation</h4></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="{{ route('/admin/resellers/{{ $reseller->id ') }}" method="POST">
@method('DELETE')
@csrf
<div class="modal-body">
<p>Are you sure you, want to delete?</p>
<input type="hidden" name="reseller-id" id="reseller-id" value="">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" data-dismiss="modal"><i class="fas fa-times fa-fw"></i>No, Cancel it.</button>
<button type="button" class="btn btn-primary"><i class="fas fa-check fa-fw"></i>Yes, Delete it.</button>
</div>
</form>
</div>
</div>
</div>
或者此代码在 javascript
中是否正确
$('#deletes').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget)
var reseller-id = button.data('resellerid')
var modal = $(this)
modal.find('.modal-body #reseller-id').val(reseller-id);
})
多次感谢您的参与。
在 blade route()
方法将起作用,如果你有名称路由。但是您没有定义任何名称路由,所以它将是:
<form action="{{ url('/admin/resellers/' . $reseller->id) }}" method="POST">
如果要使用name route,则将route name定义为:
Route::delete('/admin/resellers/{reseller}','ResellerController@destory')->name('destoryReseller');
然后你就可以这样使用了:
<form action="{{ route('destoryReseller', $reseller->id) }}" method="POST">
我在 Laravel 中创建了分页,我还创建了删除按钮,允许我删除记录,这些记录效果很好。我的下一步是用 bootstrap 模式升级删除按钮。 bootstrap 模态单独工作正常,无需在模态主体内放置任何代码。在我将粘贴的删除代码复制到模态主体内后,出现错误:
Route [/admin/resellers/{{ $reseller->id ] not defined. (View:
但我不明白的是,此路由代码在 Laravel 代码中工作正常,但在 bootstrap 模态代码中不起作用,因为两者是相同的代码!为什么!我花了一个小时想弄清楚,任何想法!
在添加到 bootstrap 代码之前,如果工作正常 Laravel(没有 bootstrap 模态)。
<td class="center">
<form action="/admin/resellers/{{ $reseller->id }}" method="POST">
<strong><a href="/admin/resellers/{{ $reseller->id }}" class="btn btn-primary btn-sm btn-mini" >
<i class="fas fa-pen fa-fw"></i>View</a></strong>
@method('DELETE')
@csrf
<button class="btn btn-secondary btn-sm btn-mini"><i class="far fa-edit fa-fw"></i>Edit
<button class="btn btn-danger btn-sm btn-mini" ><i class="fas fa-times fa-fw"></i>Delete</button>
</form>
按钮触发模式
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#deletes">
<i class="fas fa-times fa-fw"></i>Delete</button>
在路由器中
Route::delete('/admin/resellers/{reseller}','ResellerController@destory');
内部 bootstrap 模态相同删除编码
<!-- Delete Modal -->
<div class="modal modal-danger fade" id="deletes" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title text-center" id="exampleModalLabel"><h4 class="modal-title">Delete Confirmation</h4></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="{{ route('/admin/resellers/{{ $reseller->id ') }}" method="POST">
@method('DELETE')
@csrf
<div class="modal-body">
<p>Are you sure you, want to delete?</p>
<input type="hidden" name="reseller-id" id="reseller-id" value="">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" data-dismiss="modal"><i class="fas fa-times fa-fw"></i>No, Cancel it.</button>
<button type="button" class="btn btn-primary"><i class="fas fa-check fa-fw"></i>Yes, Delete it.</button>
</div>
</form>
</div>
</div>
</div>
或者此代码在 javascript
中是否正确$('#deletes').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget)
var reseller-id = button.data('resellerid')
var modal = $(this)
modal.find('.modal-body #reseller-id').val(reseller-id);
})
多次感谢您的参与。
在 blade route()
方法将起作用,如果你有名称路由。但是您没有定义任何名称路由,所以它将是:
<form action="{{ url('/admin/resellers/' . $reseller->id) }}" method="POST">
如果要使用name route,则将route name定义为:
Route::delete('/admin/resellers/{reseller}','ResellerController@destory')->name('destoryReseller');
然后你就可以这样使用了:
<form action="{{ route('destoryReseller', $reseller->id) }}" method="POST">