如何在laravel

时间:2017-05-30 05:30:07

标签: laravel-5 pivot-table

我很困惑如何获取created_at表中的pivot列。我的exam_user表包含created_atupdated_at列。现在,我的观点中有这个代码:

@if($exam->users()->where('user_id', Auth::user()->id)->exists())
    {{ Auth::user()->assignments()->pivot->created_at }}
    <div class="alert alert-success">You have done with this exam.</div>
@else

对此有何想法?

1 个答案:

答案 0 :(得分:9)

设置关系时,需要指定该数据透视表是否有时间戳。

 public function things() {
        return $this->belongsToMany('App\Thing')->withTimestamps();
    }

编辑:

尝试Auth::user()->assignments()->first()->pivot->created_at