Mr. J
Mr. J

Reputation: 245

How to get the created_at in pivot table in laravel

Im confused how to get the created_at column in my pivot table. I have exam_user table with created_at and updated_at column. Now, I have this code in my view:

@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

Any idea for this?

Upvotes: 5

Views: 4772

Answers (1)

Jagrati
Jagrati

Reputation: 12222

When setting up your relationships, you need to specify if that pivot table has timestamps.

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

Edit:

try Auth::user()->assignments()->first()->pivot->created_at

Upvotes: 23

Related Questions