【问题标题】:How we fetch data on Bootstrap modal box using Laravel MySQL我们如何使用 Laravel MySQL 在 Bootstrap 模态框中获取数据
【发布时间】:2020-05-31 11:50:21
【问题描述】:

我使用 Laravel 应用程序,我们在数据表上显示数据。当我们使用 Foreach 使用 Bootstrap 模态框更新数据时,只获取表中的最后一个数据。

我们链接的按钮:

@foreach($patients as $patient)<br>
    <li>
        <button type="button"
            class="btn btn-primary btn-sm"
            data-toggle="modal"
            data-target="#myModal{{$patient->patient_id}}">Update Fee</button>
    </li>
@endforeach

模态框:

<div id="myModal{{$patient->patient_id}}" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title"><span class="glyphicon glyphicon-edit"></span>&nbsp;Edit Fee</h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <label> Total Fee</label>
                        <input type="text" name="fee" class="form-control" readonly value="{{$patient->Fee->Fee}}" />
                        <input type="hidden" name="id" class="form-control">
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

【问题讨论】:

  • 你能给我们看一些代码吗?让我们知道你做了什么?还有什么问题
  • 你在循环模式吗?
  • 是的,循环引导模型框,但只获取最后一个ID而不是全部,如何解决它

标签: php html mysql laravel


【解决方案1】:

只需在 @foreach 指令(您的循环)中插入您的模式,这应该适用于您当前的代码。

@foreach($patients as $patient)<br>
<li>
    <button type="button"
            class="btn btn-primary btn-sm"
            data-toggle="modal"
            data-target="#myModal{{$patient->patient_id}}">Update Fee</button>
</li>

<div id="myModal{{$patient->patient_id}}" class="modal fade" role="dialog">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title"><span class="glyphicon glyphicon-edit"></span>&nbsp;Edit Fee</h4>
        </div>
        <div class="modal-body">
            <form>
                <div class="form-group">
                    <label> Total Fee</label>
                    <input type="text" name="fee" class="form-control" readonly value="{{$patient->Fee->Fee}}" />
                    <input type="hidden" name="id" class="form-control">
                </div>
            </form>
        </div>
    </div>
</div>
@endforeach

【讨论】:

    猜你喜欢
    • 2018-03-08
    • 1970-01-01
    • 2020-08-19
    • 2020-11-26
    • 2015-07-14
    • 2011-03-30
    • 2013-06-04
    • 2021-06-19
    • 2013-08-01
    相关资源
    最近更新 更多