【发布时间】:2018-11-21 13:28:18
【问题描述】:
我正在使用 Laravel 和 mysql。我正在尝试创建一个视图,在引导模式中单独显示我的每一行数据
我在每一行都有自己的特定列中放置了一个触发按钮 但我的问题是,我为每一行获取了表(数据库中)最后一行的数据(我的意思是即使我点击第二行按钮,相同的数据也会在我的模式上重复自身)。
这是我的模态:
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalCenterTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="table-responsive">
<div hidden class=" tablesaw-bar tablesaw-mode-stack"></div>
<table border="1px"class="tablesaw tablesaw-stack" data-tablesaw-mode="stack">
<head>
<tr>
<th>User name</th>
</tr>
</head>
<body>
<tr>
<td>{{$user->name}}</td>
</tr>
</body>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
这是我的按钮
<td>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
Show data
</button>
</td>
已解决
感谢 Jeff 提到的解决方案是使用我的对象的 id 我不知道如何解释但我已将模态放入我的元素中,因此它现在可以按照 Jeff 的解决方案工作。
@foreach($sujets as $sujet)
<tr>
<td>{{$sujet->nomsujet}}</td>
<td>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter{{$sujet->id}}">
show data
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter{{$sujet->id}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalCenterTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="table-responsive">
<div hidden class=" tablesaw-bar tablesaw-mode-stack"></div>
<table border="1px"class="tablesaw tablesaw-stack" data-tablesaw-mode="stack">
<head>
<tr>
<th>Date </th>
</tr>
</head>
<body>
<tr>
<td>{{$sujet->date}}</td>
</tr>
</body>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</td>
</tr>
@endforeach
【问题讨论】:
-
请将您的解决方案转移到自己的答案中,谢谢。
标签: laravel modal-dialog