Pivot model UPDATED_AT = null; ignored when using attach()
Laravel Version
12.0
PHP Version
8.4.11
Database Driver & Version
No response
Description
When using a custom pivot model, defining const UPDATED_AT = null; inside the pivot model is ignored. Instead, Laravel seems to respect the parent (main) model’s timestamp settings.
Models
AnnouncementUserAnnouncementUser(custom pivot model)
Code Example
$announcement->users()->attach($userIds);
Expected Behavior
Since the pivot model AnnouncementUser has:
class AnnouncementUser extends Pivot
{
const UPDATED_AT = null;
}
I expect the updated_at column to be ignored during attach().
Actual Behavior
Laravel still tries to insert/update the updated_at column, resulting in:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in ...
Workaround
If I move
const UPDATED_AT = null;
to the Announcement model, the error disappears.
This suggests that the parent model overrides the pivot model’s UPDATED_AT configuration.
Steps To Reproduce
Create three models: Announcement, User, and a custom pivot model AnnouncementUser extending Illuminate\Database\Eloquent\Relations\Pivot.
In the AnnouncementUser model, set:
class AnnouncementUser extends Pivot
{
const UPDATED_AT = null;
}
Define the many-to-many relationship in the Announcement model:
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class)
->using(AnnouncementUser::class);
}
Run the following code:
$announcement->users()->attach($userIds);
Observe the error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in ...