简体   繁体   English

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

[英]Combine data from two mysql tables in HTML table Laravel 5.4

Trying to make one html table where is showing what login users choose. 尝试制作一个html表,其中显示登录用户选择的内容。 One login auth users and one form data. 一个登录身份验证用户和一个表单数据。 Here data is showing on page but scramled in table. 这里的数据显示在页面上,但在表中却乱七八糟。 Homedata is showing twice. Homedata显示两次。 Here is my index page where im trying to do: 这是我尝试做的我的索引页:

 <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>

Please help. 请帮忙。 if there is another way please feel free suggest. 如果还有其他方法,请随时提出建议。

Hey everyone who share the same problem. 嘿,每个共享相同问题的人。 I add in second foreach ->slice(0, 1) and that foreach just going once, that automaticaly means no duplicate data :) 我添加第二个foreach-> slice(0,1),并且foreach仅执行一次,这意味着没有重复的数据:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM