blade 模板中的模式 window 显示所有记录而不是选定的 ID

Modal window in blade template shows all records instead of selected ID(s)

我在页面上有 table,其中列出了用户拥有的所有订单。每个订单可以有 1 个或多个附加文件和一个下载按钮。基本上,如果用户有 2 个订单,他的页面上将有 2 个按钮

<a href="#files-{{ $download->order_id }}">Download</a> // order 1
<a href="#files-{{ $download->order_id }}">Download</a> // order 2

单击该按钮可打开模式 window,其中列出文件并 link 下载。

这是模态window

        <span id="start" class="target"></span>
        <span id="files-{{ $download->order_id }}" class="target"></span>
        <div class="modal">
            <div class="content vertical-align-middle">
                <h2>Click on the button to download it</h2>
                <table class="table table-striped">
                  <thead id="tblHead">
                    <tr>
                      <th align="center">File</th>
                      <th align="center">Action</th>
                    </tr>
                  </thead>
                  <tbody>
                    @foreach($downloadableOrders as $files)                     
                        @if($files->status == 1)
                            {{--*/ $ids = explode(",", $files->docname); /*--}}
                            @foreach ($ids as $id)
                                <tr>
                                  <td></td>
                                  <td><a href="{{ URL::to('/files/download/' . $id . '?_token=' . csrf_token()) }}">Download</a></td>
                                </tr>
                            @endforeach
                        @endif
                    @endforeach
                  </tbody>
                </table>
                <a class="close-btn" href="#start">X</a>
            </div>
        </div>

这是使用的查询

$downloadableOrders = Order::where('user_id', getCurrentUser()->user_id)
               ->select("orders.*",\DB::raw("GROUP_CONCAT(documents.id  ) as docname"))
               ->leftjoin("documents",\DB::raw("FIND_IN_SET(documents.id,orders.order_downloadable)"),">",\DB::raw("'0'"))
               ->groupBy("orders.order_id")
              ->paginate(10);

问题是当模式打开时它会列出所有订单和所有文件。应该只为点击的订单列出文件。

您将必须使用 ajax 打开模态框。所以你需要做的是当你点击下载时link ajax会执行,获取数据并显示在模态框中。