-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.4] Add Model::refresh() #19174
[5.4] Add Model::refresh() #19174
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -943,6 +943,23 @@ public function fresh($with = []) | |
->first(); | ||
} | ||
|
||
/** | ||
* Reload the current model instance with fresh attributes from the database. | ||
* | ||
* @param array|string $with | ||
* @return static|null | ||
*/ | ||
public function refresh() | ||
{ | ||
if (! $this->exists) { | ||
return; | ||
} | ||
|
||
$this->load(array_keys($this->relations)); | ||
|
||
$this->setRawAttributes(static::find($this->getKey())->attributes); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the model was deleted exists would return false and the method will just bail. |
||
} | ||
|
||
/** | ||
* Clone the model into a new, non-existing instance. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No param