Skip to content

Commit

Permalink
[11.x] Fix determining pivot timestamp column name(s) when parent rel…
Browse files Browse the repository at this point in the history
…ation missing one or both of timestamps (laravel#53103)

Co-authored-by: Sergey Danilchenko <[email protected]>
  • Loading branch information
2 people authored and timacdonald committed Oct 15, 2024
1 parent 98de0f1 commit e0f0e39
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ class BelongsToMany extends Relation
/**
* The custom pivot table column for the created_at timestamp.
*
* @var string
* @var string|null
*/
protected $pivotCreatedAt;

/**
* The custom pivot table column for the updated_at timestamp.
*
* @var string
* @var string|null
*/
protected $pivotUpdatedAt;

Expand Down Expand Up @@ -1478,7 +1478,7 @@ public function withTimestamps($createdAt = null, $updatedAt = null)
*/
public function createdAt()
{
return $this->pivotCreatedAt ?: $this->parent->getCreatedAtColumn();
return $this->pivotCreatedAt ?? $this->parent->getCreatedAtColumn() ?? Model::CREATED_AT;
}

/**
Expand All @@ -1488,7 +1488,7 @@ public function createdAt()
*/
public function updatedAt()
{
return $this->pivotUpdatedAt ?: $this->parent->getUpdatedAtColumn();
return $this->pivotUpdatedAt ?? $this->parent->getUpdatedAtColumn() ?? Model::UPDATED_AT;
}

/**
Expand Down

0 comments on commit e0f0e39

Please sign in to comment.