Laravel - belongsToMany关系时间戳

So I have a pivot table called thread_user and I have two models; User.php and Thread.php.

I have this in my User.php file:

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

I only want the created_at timestamp though. I don't want updated_at and every time I try to attach something to the pivot table, I get this error: Column not found: 1054 Unknown column 'updated_at' in 'field list'.... It is really annoying. I can't have the updated_at timestamp for some reason but I still do want the created_at timestamp.

Please let me know how I can fix this. I have tried the following with no luck:

return $this->belongsToMany('App\Thread')->withTimestamps(['created_at']);

Please help. Thanks!

Since you're not using both timestamps, you need to remove the call to withTimestamps() and just call withPivot() for the field that you do have.

So, your code should look like:

public function threads()
{
    return $this->belongsToMany('App\Thread')->withPivot('created_at');
}