From 5d8dce36f55551c4fed232ddf3d0c66327c5bba3 Mon Sep 17 00:00:00 2001 From: Ryan Leach Date: Wed, 15 Jan 2020 09:11:18 -0600 Subject: [PATCH] Added support for fresh method --- src/Model/Traits/HasCompositePrimaryKey.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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(); + } }