Skip to content

Commit 092db4e

Browse files
Add documentation for getChanges (#10258)
* Add documentation for getChanges The eloquent method getOriginal is already documented, and we should do the same with getChanges. * Update eloquent.md --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 4223ed3 commit 092db4e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

eloquent.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -872,13 +872,36 @@ $user = User::find(1);
872872
$user->name; // John
873873
$user->email; // [email protected]
874874

875-
$user->name = "Jack";
875+
$user->name = 'Jack';
876876
$user->name; // Jack
877877

878878
$user->getOriginal('name'); // John
879879
$user->getOriginal(); // Array of original attributes...
880880
```
881881

882+
The `getChanges` method returns an array containing the attributes that changed when the model was last saved:
883+
884+
```php
885+
$user = User::find(1);
886+
887+
$user->name; // John
888+
$user->email; // [email protected]
889+
890+
$user->update([
891+
'name' => 'Jack',
892+
'email' => '[email protected]',
893+
]);
894+
895+
$user->getChanges();
896+
897+
/*
898+
[
899+
'name' => 'Jack',
900+
'email' => '[email protected]',
901+
]
902+
*/
903+
```
904+
882905
<a name="mass-assignment"></a>
883906
### Mass Assignment
884907

0 commit comments

Comments
 (0)