File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -521,6 +521,16 @@ public function syncOriginalAttribute($attribute): static
521521 return $ this ->syncOriginalAttributes ($ attribute );
522522 }
523523
524+ /**
525+ * Discard attribute changes and reset the attributes to their original state.
526+ */
527+ public function discardChanges (): static
528+ {
529+ [$ this ->attributes , $ this ->changes ] = [$ this ->original , []];
530+
531+ return $ this ;
532+ }
533+
524534 /**
525535 * Sync multiple original attribute with their current values.
526536 *
Original file line number Diff line number Diff line change @@ -206,6 +206,23 @@ public function testArrayAccessToAttributes()
206206 $ this ->assertFalse (isset ($ model ['with ' ]));
207207 }
208208
209+ public function testDiscardChanges ()
210+ {
211+ $ user = new ModelStub ([
212+ 'name ' => 'Taylor Otwell ' ,
213+ ]);
214+
215+ $ this ->assertNotEmpty ($ user ->isDirty ());
216+ $ this ->assertNull ($ user ->getOriginal ('name ' ));
217+ $ this ->assertSame ('Taylor Otwell ' , $ user ->getAttribute ('name ' ));
218+
219+ $ user ->discardChanges ();
220+
221+ $ this ->assertEmpty ($ user ->isDirty ());
222+ $ this ->assertNull ($ user ->getOriginal ('name ' ));
223+ $ this ->assertNull ($ user ->getAttribute ('name ' ));
224+ }
225+
209226 public function testOnly ()
210227 {
211228 $ model = new ModelStub ();
You can’t perform that action at this time.
0 commit comments