在HTML表Laravel 5.4中组合来自两个mysql表的数据

时间:2018-04-08 17:40:41

标签: php laravel laravel-5.4

尝试制作一个html表,显示登录用户选择的内容。 一个登录auth用户和一个表单数据。 这里的数据显示在页面上,但在表格中填写。 Homedata正在展示两次。 这是我想要做的索引页面:

 <table class="table" id="users-info">
                      <thead>
                        <tr>
                          <th scope="col">#</th>
                          <th scope="col">First Name</th>
                          <th scope="col">Last Name</th>
                          <th scope="col">Naional Number</th>
                          <th scope="col">Device</th>
                          <th scope="col">Reimbursment</th>
                          <th scope="col">Warranty</th>
                        </tr>
                      </thead>
                      <tbody>
                     @if(count($users) > 0)
                                @foreach($users as $user)

                                    <tr>
                                      <th scope="row">{{ $user->id }}</th>
                                      <td>{{ $user->firstname }}</td>
                                      <td>{{ $user->lastname }}</td>
                                      <td>{{ $user->phone }}

                                    @foreach($homedata as $homedatas)

                                          <td>{{$homedatas->device}}</td>
                                          <td>{{$homedatas->reimburse_Pension}}</td>
                                          <td>{{$homedatas->bonus_remainder}}</td>          
                                    @endforeach
                                    </td>
                                    </tr>
                                @endforeach     
                            @endif  
                      </tbody>
                </table>

请帮忙。 如果有其他方式,请随意建议。

1 个答案:

答案 0 :(得分:0)

嘿大家都有同样的问题。 我添加了第二个foreach - &gt; slice(0,1)和foreach只进行一次,自动意味着没有重复数据:)

相关问题