2017-05-30 15 views
0

林困惑如何在我的pivot表得到created_at列。我有exam_usercreated_atupdated_at列。现在,我有这样的代码在我看来:

如何获得在透视表中的created_at在laravel

@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 

这个任何想法?

回答

3

当设置你的关系,你需要指定如果数据透视表有时间戳。

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

编辑:

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

+0

我已经做到了。 –

+0

尝试'验证::用户() - >分配() - >第一个() - > pivot-> created_at' – Jagrati

+0

其刚刚起步的第一个结果。我想用当前视图来获取当前分配 –

相关问题