Skip to content

Commit d52c6f1

Browse files
committed
add a refresh() method for models
1 parent 584491a commit d52c6f1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/database/src/IsDatabaseModel.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ public static function updateOrCreate(array $find, array $update): self
116116
return $model->save();
117117
}
118118

119+
public function refresh(): self
120+
{
121+
$model = self::find(id: $this->id)->first();
122+
foreach (new ClassReflector($model)->getPublicProperties() as $property) {
123+
$property->setValue($this, $property->getValue($model));
124+
}
125+
126+
return $this;
127+
}
128+
119129
public function __get(string $name): mixed
120130
{
121131
$property = PropertyReflector::fromParts($this, $name);

0 commit comments

Comments
 (0)