从表中删除数据 - Laravel

时间:2018-04-20 10:40:36

标签: php laravel

我正在尝试创建一个删除模式框,而不是使用JS的基本警报。下面,我特意将模态框放在表格中的for循环中,分别删除每个条目。

当我点击删除链接时,它不会弹出模态框?为什么会这样?

<table id="myTable" class="table table-xl mb-0">
  <thead>
    <tr>
      <th>Name</th>
      <th>File</th>
      <th>Action</th>
    </tr>
  </thead>
  <tbody>
    @foreach($entries as $entry)
    <tr>
      <td>{{$entry->id}}</td>
      <td>{{$entry->file}}</td>
      <td>
        <a href="/file/{{$entry->id}}/checks"></a>
        <a href="#deleteModal_{{ $entry->id }}" data-toggle="modal" data-target="#myModal"></a>

        <div id="deleteModal_{{ $entry->id }}" class="modal fade" id="myModal" role="dialog">
          <div class="modal-dialog">

            <div class="modal-content">
              <div class="modal-header">
              </div>

              <div class="modal-body">
                <p>Do you wish to delete this {{$entry->name}} file?</p>
              </div>

              <div class="modal-footer">
                <a href="'/files/{{$entry->id}}/delete'" class="yes">Yes</a>
                <a data-dismiss="modal" class="no">No</a>      
              </div>
            </div>

          </div>
        </div>         
        </div>
      </td>
    </tr>
    @endforeach
  </tbody>
</table>

2 个答案:

答案 0 :(得分:0)

你有两倍于模态div

中定义的id
 id="deleteModal_{{ $entry->id }}" class="modal fade" id="myModal"

删除第二个ID并重命名

data-target="#myModal"

data-target="#deleteModal_{{ $entry->id }}"

答案 1 :(得分:0)

替换以下两行

   <a  href="#"  data-toggle="modal" data-target="#deleteModal_{{ $entry->id }}"></a>

   <div id="deleteModal_{{ $entry->id }}" class="modal fade" role="dialog">

你必须在#tag的锚标记href属性的数据目标属性中添加模态路径,并删除id =&#34; myModal&#34;来自div