【发布时间】:2019-06-20 07:16:24
【问题描述】:
请我想删除基于其data-id 的特定记录为:data-id="delete-form-{{ $position->id }},但无论何时我尝试它总是返回最后一个记录 ID,甚至无法删除。
下面是我的代码
@forelse ($pos as $position)
<tr>
<td>{{ $loop->index+1 }}</td>
<td>{{ $position->name }}</td>
<td>{{ $position->created_at->diffForHumans() }}</a></td>
<td><a class="btn btn-warning" href="{{ route('position.edit', $position->id) }}"><i class="fa fa-fw fa-lg fa-edit"></i>Edit</a></td>
<td>
<form data-id="delete-form-{{ $position->id }}" action="{{ route('position.destroy', $position->id) }}" method="POST" style="display:none">
@csrf
@method('DELETE')
</form>
<a class="posSwal btn btn-sm btn-danger" href="" onclick="isConfirm()">
<i class="fa fa-fw fa-lg fa-times-circle"></i>Delete</a>
</td>
</tr>
@empty
<p>No Record available</p>
@endforelse
JavaScript
<script>
$('.posSwal').click(function(){
event.preventDefault();
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false
}, function(isConfirm) {
if (isConfirm) {
$("form").data("id").submit();
swal("Deleted!", "Your imaginary file has been deleted.", "success");
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
});
【问题讨论】:
标签: javascript php jquery twitter-bootstrap laravel-5