From f1584bff48c8993eadcacd459d3db822f6cb387f Mon Sep 17 00:00:00 2001 From: Patrick O'Meara Date: Thu, 2 Nov 2017 00:58:52 +1100 Subject: [PATCH] syncOriginal on refresh (#21905) --- src/Illuminate/Database/Eloquent/Model.php | 2 ++ .../Database/EloquentModelRefreshTest.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index b47d653d8712..e5246a0413fe 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -1006,6 +1006,8 @@ public function refresh() $this->load(collect($this->relations)->except('pivot')->keys()->toArray()); + $this->syncOriginal(); + return $this; } diff --git a/tests/Integration/Database/EloquentModelRefreshTest.php b/tests/Integration/Database/EloquentModelRefreshTest.php index 9687f5d32805..aa4b9828c7f1 100644 --- a/tests/Integration/Database/EloquentModelRefreshTest.php +++ b/tests/Integration/Database/EloquentModelRefreshTest.php @@ -63,6 +63,22 @@ public function it_refreshes_a_soft_deleted_model() $this->assertTrue($post->trashed()); } + + /** + * @test + */ + public function it_syncs_original_on_refresh() + { + $post = Post::create(['title' => 'pat']); + + Post::find($post->id)->update(['title' => 'patrick']); + + $post->refresh(); + + $this->assertEmpty($post->getDirty()); + + $this->assertEquals('patrick', $post->getOriginal('title')); + } } class Post extends Model