diff --git a/src/Model/Traits/HasCompositePrimaryKey.php b/src/Model/Traits/HasCompositePrimaryKey.php index 3853378..0dd1387 100644 --- a/src/Model/Traits/HasCompositePrimaryKey.php +++ b/src/Model/Traits/HasCompositePrimaryKey.php @@ -111,4 +111,21 @@ public function refresh() return $this; } + + /** + * Reload a fresh model instance from the database. + * + * @param array|string $with + * @return static|null + */ + public function fresh($with = []) { + if (!$this->exists) { + return; + } + + return static::newQueryWithoutScopes() + ->with(is_string($with) ? func_get_args(): $with) + ->where($this->getKey()) + ->first(); + } }