From dd59f62a32ec99e9451bdadc62b99834f337551a Mon Sep 17 00:00:00 2001 From: rogatty <7030884+rogatty@users.noreply.github.com> Date: Fri, 18 Mar 2022 08:27:50 +0100 Subject: [PATCH] Stop throwing when lazy loading used in recently created model --- src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php index 1cdf24375bb5..a208249f8281 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php @@ -519,6 +519,10 @@ protected function handleLazyLoadingViolation($key) return call_user_func(static::$lazyLoadingViolationCallback, $this, $key); } + if (!$this->exists || $this->wasRecentlyCreated) { + return; + } + throw new LazyLoadingViolationException($this, $key); }