I seem to have a problem with timestamps - when trying to attach User
to Lectures
via favorites
pivot table - none of the dates updates.
以下是我的迁移:
Schema::create('favorites', function (Blueprint $table) {
$table->integer('lecture_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->timestamps();
$table->primary(['lecture_id', 'user_id']);
});
讲座关系:
public function favorites()
{
return $this->belongsToMany(User::class, 'favorites');
}
用户关系:
public function favorites()
{
return $this->belongsToMany(Lecture::class, 'favorites')
->withTimestamps();
}
每当我附上:
$event->lecture->favorites()->attach($this->user->id);
Both fields created_at
and updated_at
are set to 0000-00-00 00:00:00
知道我做错了什么吗?