From 6c663f0b134a58bb8c01a251e89e10156931795c Mon Sep 17 00:00:00 2001 From: Sergey Danilchenko Date: Thu, 10 Oct 2024 17:12:50 +0200 Subject: [PATCH] [11.x] Fix determining pivot timestamp column name(s) when parent relation missing one or both of timestamps --- .../Database/Eloquent/Relations/BelongsToMany.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php index 121abb5b026c..161352c7b613 100755 --- a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php @@ -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; @@ -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; } /** @@ -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; } /**