我很困惑如何获取created_at
表中的pivot
列。我的exam_user
表包含created_at
和updated_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
对此有何想法?
答案 0 :(得分:9)
设置关系时,需要指定该数据透视表是否有时间戳。
public function things() {
return $this->belongsToMany('App\Thing')->withTimestamps();
}
编辑:
尝试Auth::user()->assignments()->first()->pivot->created_at