【问题标题】:laravel how can i show the pivot: data from the get() methodlaravel 我如何显示枢轴:来自 get() 方法的数据
【发布时间】:2020-04-01 12:39:15
【问题描述】:

当我有 get 函数时,我有以下数据正在检索:

{"id":2,"ticketnaam":"testticket2","ticketprijs":"6000","created_at":"2020-03-27
12:50:24","updated_at":"2020-03-27
12:50:24","pivot":{"user_id":2,"ticket_id":2,"tijd":"09:00:00","beschrijving":"test"}}

我想显示枢轴项目“tijd”和“bechrijving”,但是当我尝试检索它时,它只是没有显示任何错误或其他东西。

我的刀片:

                    <div class="card-body ">
                        <table class="table">
                            <thead>
                            <tr>
                                <th scope="col">Strippenkaart</th>
                                <th scope="col">Tijd</th>
                                <th scope="col">Beschrijving</th>
                                <th scope="col">Actions</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($details as $detail)
                            <tr>
                                <td>
                                    {{$detail->ticketnaam}}
                                </td>
                                <td>
                                    {{$detail->tijd}}
                                </td>
                                <td>
                                    {{$detail->beschrijving}}
                                </td>
                                <td>
                                </td>
                            </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>

我的用户模型:

    public function tickets(){

        return $this->belongsToMany('App\Ticket')->withPivot('tijd','beschrijving');
    }

【问题讨论】:

  • detail-&gt;pivot-&gt;tijddetail-&gt;pivot-&gt;beschrijving
  • 欢迎您....

标签: php database laravel


【解决方案1】:

我认为可以这样做:

{{ $detail-&gt;pivot-&gt;tijd }}

{{ $detail-&gt;pivot-&gt;beschrijving }}

试试吧!!

【讨论】:

  • 很高兴为您提供帮助 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-11-23
  • 1970-01-01
  • 2021-07-16
  • 1970-01-01
  • 1970-01-01
  • 2017-06-13
  • 1970-01-01
相关资源
最近更新 更多