如何使用laravel获取模态确认删除显示数据? [英] How to get modal confirm delete showing the data using laravel?
问题描述
当我尝试删除行之一(数据之一)时,我想从表或数据库中获取值id.我试图扩展我的 endforeach
,这只是使html变得如此怪异.嗯,这里有更多的解释是我的照片.
i want to get value id from my table or my db , when i tried to delete one of the row (one of the data). I tried to expand my endforeach
and it's just make the html become so weird. Um for more explaining here is my images.
图像确认模式
是的,我只是想确认用户是否单击了删除按钮,它会显示一个模态您确定要删除它吗?".因此,问题是,我不知道如何获取该值当我单击第二行删除按钮中的下一个删除按钮,第三行删除按钮中的删除按钮,第四行删除按钮中的删除按钮(如果有下面的行)时,id等.
yeah i just want to confirm the user if it clicked the delete button it will show a modal "are you sure you want to delete this?".So, the problem is, i don't know how to get the value id when i clicked the next delete button from the seccond row delete button, delete button from the third row delete button, delete button from the fourth row delete button (if there is a row bellow it) and so on.
这是我的模式代码
模式删除
<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_id
的值.使用零(0)硬代码.例如,如果我要删除下一个索引(下一个索引),即1,如果要删除下一个索引,如何将其值更改为1或将值更改为2,等等.基本上,我希望该功能更像是当我单击某一行中的删除按钮时,它将显示该行中的id程序.我目前正在使用laravel和php.我不知道该如何实现.有人可以帮我吗?
i'm just make the value of index $ideaprogram[0]->showidea_id
like that. Using zero (0) the hardcode. for example if i want to delete the next one (the next index) which is 1, how can i change it the value into 1 or change it the value into 2 if i want to delete the next index and so on. Basically i want the function more like when i clicked the delete button from some row, it will show the id program from that row. I'm using laravel and php at the moment. I don't know how to make it happen. Can someone help me?
推荐答案
实际上,我想要一个能给我一个类似于AA Noman的解决方案的答案,因为这对于一小段代码来说是很好的,所以我坚信这是可能的,但是在尝试了建议的解决方案之后,并没有给我我想要的,所以我认为我可以这样解决.
Actually i want an answer that give me a solutions more like A.A Noman since it will be good for a little line of code, so i tought it possible, but after trying the suggested solutions, and not give me that i want, so i think i can solve it like this.
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
无论如何,感谢大家回答我的问题
anyway thank you for everyone that answer my questions
这篇关于如何使用laravel获取模态确认删除显示数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!