From c540beb375e43470da2796207ad52231525679b2 Mon Sep 17 00:00:00 2001 From: Choraimy Kroonstuiver <3661474+axlon@users.noreply.github.com> Date: Wed, 14 Oct 2020 16:37:59 +0200 Subject: [PATCH] Fix fresh and refresh on pivots and morph pivots --- src/Illuminate/Database/Eloquent/Model.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index d836e6de7999..22ceca188fd3 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -1207,9 +1207,8 @@ public function fresh($with = []) return; } - return static::newQueryWithoutScopes() + return $this->setKeysForSaveQuery(static::newQueryWithoutScopes()) ->with(is_string($with) ? func_get_args() : $with) - ->where($this->getKeyName(), $this->getKey()) ->first(); } @@ -1225,7 +1224,7 @@ public function refresh() } $this->setRawAttributes( - static::newQueryWithoutScopes()->findOrFail($this->getKey())->attributes + $this->setKeysForSaveQuery(static::newQueryWithoutScopes())->firstOrFail()->attributes ); $this->load(collect($this->relations)->reject(function ($relation) {