Php 如何使用laravel获取显示数据的模态确认删除?
当我试图删除其中一行(其中一个数据)时,我想从表或数据库中获取值id。我试着扩展我的Php 如何使用laravel获取显示数据的模态确认删除?,php,laravel,Php,Laravel,当我试图删除其中一行(其中一个数据)时,我想从表或数据库中获取值id。我试着扩展我的endforeach,结果却让html变得如此怪异。嗯,更多的解释请看我的图片 图像确认模式 是的,我只是想确认用户如果单击了删除按钮,它将显示一个模式“你确定要删除此吗?”。因此,问题是,当我从第二行删除按钮单击下一个删除按钮时,我不知道如何获取值id,从第三行删除按钮单击删除按钮时,删除按钮从第四行删除按钮(如果它下面有一行),依此类推 这是我的模式代码 模式删除 <div class="m-2"&g
endforeach
,结果却让html变得如此怪异。嗯,更多的解释请看我的图片
图像确认模式
是的,我只是想确认用户如果单击了删除按钮,它将显示一个模式“你确定要删除此吗?”。因此,问题是,当我从第二行删除按钮单击下一个删除按钮时,我不知道如何获取值id,从第三行删除按钮单击删除按钮时,删除按钮从第四行删除按钮(如果它下面有一行),依此类推
这是我的模式代码
模式删除
<div class="m-2">
<div class="modal fade h-50" id="modalDelete" tabindex="-1" role="dialog" aria-
labelledby="deleteModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModal">Change Department Status</h5>
</div>
<div class="modal-body">
<p id="question">Are You sure want to delete {{$ideaprogram[0]->showidea_id}}?</p>
</div>
<div class="modal-footer">
<a id="deleteData">
<button type="button" class="btn btn-success">Yes</button>
</a>
<button type="button" class="btn btn-danger" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
</div>
更改部门状态
是否确实要删除{{{$ideaprogram[0]->showidea\u id}
对
不
我只是将index
$ideaprogram[0]->showidea\u id的值设置为那样。使用零(0)表示硬代码。例如,如果我要删除下一个(下一个索引),即1,我如何将其值更改为1,或者如果我要删除下一个索引,如何将其值更改为2,依此类推。基本上,我想要的功能更像我从某一行单击delete按钮时,它将显示该行的id程序。目前我正在使用laravel和php。我不知道如何让它发生。有人能帮我吗?在删除按钮上的模式中设置数据单击:
假设您正在表中显示数据,则为属性数据programid指定“删除”按钮
@foreach($programs as $program)
<tr>
<td>{{$program->name}}</td>
<td><button class="btn btn-danger deleteProgram" data-programid="{{$program->id}}">Delete</button></td>
</tr>
@endforeach
@foreach($programs作为$program)
{{$program->name}
删除
@endforeach
现在,当用户单击DeleteProgramButton类javascript时,我们在模式中设置数据并显示模式
<script>
$(document).on('click','.deleteProgram',function(){
var programID=$(this).attr('data-programid');
$('#app_id').val(programID);
$('#question').append(programID+' ?');
$('#applicantDeleteModal').modal('show');
});
</script>
$(文档)。在('单击','.deleteProgram',函数()上{
var programID=$(this.attr('data-programID');
$('#app_id').val(programID);
$(“#问题”).append(programmaid+”?);
$('#applicationDeleteModal').modal('show');
});
你的模态:
<div id="applicantDeleteModal" class="modal modal-danger fade" tabindex="-1" role="dialog" aria-labelledby="custom-width-modalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog" style="width:55%;">
<div class="modal-content">
<form action="{{route()}}" method="POST" class="remove-record-model">
{{ method_field('delete') }}
{{ csrf_field() }}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h5 class="modal-title text-center" id="custom-width-modalLabel">Change Department Status</h5>
</div>
<div class="modal-body">
<h4 id="question">Are You sure want to delete </h4>
<input type="hidden" name="applicant_id" id="app_id">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger waves-effect remove-data-from-delete-form">Delete</button>
</div>
</form>
</div>
</div>
</div>
{{method_field('delete')}
{{csrf_field()}}
×
更改部门状态
确实要删除吗
接近
删除
在删除按钮上的模式中设置数据单击:
假设您正在表中显示数据,则为属性数据programid指定“删除”按钮
@foreach($programs as $program)
<tr>
<td>{{$program->name}}</td>
<td><button class="btn btn-danger deleteProgram" data-programid="{{$program->id}}">Delete</button></td>
</tr>
@endforeach
@foreach($programs作为$program)
{{$program->name}
删除
@endforeach
现在,当用户单击DeleteProgramButton类javascript时,我们在模式中设置数据并显示模式
<script>
$(document).on('click','.deleteProgram',function(){
var programID=$(this).attr('data-programid');
$('#app_id').val(programID);
$('#question').append(programID+' ?');
$('#applicantDeleteModal').modal('show');
});
</script>
$(文档)。在('单击','.deleteProgram',函数()上{
var programID=$(this.attr('data-programID');
$('#app_id').val(programID);
$(“#问题”).append(programmaid+”?);
$('#applicationDeleteModal').modal('show');
});
你的模态:
<div id="applicantDeleteModal" class="modal modal-danger fade" tabindex="-1" role="dialog" aria-labelledby="custom-width-modalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog" style="width:55%;">
<div class="modal-content">
<form action="{{route()}}" method="POST" class="remove-record-model">
{{ method_field('delete') }}
{{ csrf_field() }}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h5 class="modal-title text-center" id="custom-width-modalLabel">Change Department Status</h5>
</div>
<div class="modal-body">
<h4 id="question">Are You sure want to delete </h4>
<input type="hidden" name="applicant_id" id="app_id">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger waves-effect remove-data-from-delete-form">Delete</button>
</div>
</form>
</div>
</div>
</div>
{{method_field('delete')}
{{csrf_field()}}
×
更改部门状态
确实要删除吗
接近
删除
我一直这样使用
<td>
<ul style="list-style-type: none;">
<li><i class="fa fa-edit"></i> <a href="{{ url('') }}/en/admin/role/edit/{{ $role->id }}"> Edit </a></li>
<li><i class="fa fa-trash"></i>
<button data-toggle="modal" data-target="#modal{{ $role->id }}">Delete</button>
</li>
</ul>
</td>
<!-- Modal -->
<div class="modal fade" id="modal{{ $role->id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header bg-danger">
<h5 class="modal-title" id="exampleModalLabel">You are about to delete the role {{ $role->title }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body text-danger">Once you delete, it cannot be undone.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<form method="POST" action="{{ url('') }}/en/admin/role/delete/{{ $role->id }}">
{{ method_field('delete') }}
{{ csrf_field() }}
<button type="submit" class="btn btn-danger">Confirm</button>
</form>
</div>
</div>
</div>
</div>
-
删除
您将要删除角色{{$role->title}
&时代;
一旦删除,就无法撤消。
接近
{{method_field('delete')}
{{csrf_field()}}
证实
我一直这样使用
<td>
<ul style="list-style-type: none;">
<li><i class="fa fa-edit"></i> <a href="{{ url('') }}/en/admin/role/edit/{{ $role->id }}"> Edit </a></li>
<li><i class="fa fa-trash"></i>
<button data-toggle="modal" data-target="#modal{{ $role->id }}">Delete</button>
</li>
</ul>
</td>
<!-- Modal -->
<div class="modal fade" id="modal{{ $role->id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header bg-danger">
<h5 class="modal-title" id="exampleModalLabel">You are about to delete the role {{ $role->title }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body text-danger">Once you delete, it cannot be undone.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<form method="POST" action="{{ url('') }}/en/admin/role/delete/{{ $role->id }}">
{{ method_field('delete') }}
{{ csrf_field() }}
<button type="submit" class="btn btn-danger">Confirm</button>
</form>
</div>
</div>
</div>
</div>
-
删除
您将要删除角色{{$role->title}
&时代;
一旦删除,就无法撤消。
接近
{{method_field('delete')}
{{csrf_field()}}
证实
事实上,我想要一个答案,给我一个更像a.a.Noman的解决方案,因为这对一小行代码很好,所以我认为这是可能的,但在尝试了建议的解决方案后,没有给我我想要的,所以我想我可以这样解决它
script.js
function deleteModal(data){
document.getElementById('question').innerHTML = `Are you sure to delete ${data.showidea_id} ?`;
document.getElementById('deleteData').setAttribute('href',`/program_idea/${data.showidea_id}/deleteData`);
$('#modalDelete').modal('show');
}
我的HTML是这样的
index.blade.php
@foreach($ideaprogram as $dataload)
<tr>
<td class="text-center">
<button type="button" class="btn btn-danger btn-sm deleteProgram" data-toggle="modal"
onclick="deleteModal({{$dataload}})">
<i class="far fa-trash-alt"></i>
</button>
</tr>
@endforeach
@foreach($ideaprogram作为$dataload)
@endforeach
无论如何,谢谢大家回答我的问题事实上,我想要一个答案,给我一个更像a的解决方案。一个普通人,因为这对一小行代码很好,所以我认为这是可能的,但在尝试了建议的解决方案后,没有给我我想要的,所以我认为我可以这样解决它
script.js
function deleteModal(data){
document.getElementById('question').innerHTML = `Are you sure to delete ${data.showidea_id} ?`;
document.getElementById('deleteData').setAttribute('href',`/program_idea/${data.showidea_id}/deleteData`);
$('#modalDelete').modal('show');
}
我的HTML是这样的
index.blade.php
@foreach($ideaprogram as $dataload)
<tr>
<td class="text-center">
<button type="button" class="btn btn-danger btn-sm deleteProgram" data-toggle="modal"
onclick="deleteModal({{$dataload}})">
<i class="far fa-trash-alt"></i>
</button>
</tr>
@endforeach
@foreach($ideaprogram作为$dataload)
@endforeach
不管怎样谢谢你