From e9f37edb195870d74cf92b06e589ab7154963e2a Mon Sep 17 00:00:00 2001 From: M N Islam Shihan Date: Mon, 5 Feb 2018 06:04:05 +0600 Subject: [PATCH] Where clauses should use original attribute values With current implementation, it is impossible to update any of the foreign or related keys in Pivot instance, without executing raw SQL queries, as the generated query is using current attribute values instead of the original values. This commit will fix this issue. --- src/Illuminate/Database/Eloquent/Relations/Pivot.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/Pivot.php b/src/Illuminate/Database/Eloquent/Relations/Pivot.php index e80aa911d567..c10f46cbe84a 100755 --- a/src/Illuminate/Database/Eloquent/Relations/Pivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Pivot.php @@ -99,9 +99,9 @@ protected function setKeysForSaveQuery(Builder $query) return parent::setKeysForSaveQuery($query); } - $query->where($this->foreignKey, $this->getAttribute($this->foreignKey)); + $query->where($this->foreignKey, $this->getOriginal($this->foreignKey)); - return $query->where($this->relatedKey, $this->getAttribute($this->relatedKey)); + return $query->where($this->relatedKey, $this->getOriginal($this->relatedKey)); } /** @@ -126,8 +126,8 @@ public function delete() protected function getDeleteQuery() { return $this->newQuery()->where([ - $this->foreignKey => $this->getAttribute($this->foreignKey), - $this->relatedKey => $this->getAttribute($this->relatedKey), + $this->foreignKey => $this->getOriginal($this->foreignKey), + $this->relatedKey => $this->getOriginal($this->relatedKey), ]); }