From 85519b56151b345e3e50b53a1ae04ba03abefcd8 Mon Sep 17 00:00:00 2001 From: Nikolay Novikov Date: Sat, 20 May 2023 22:51:03 +0300 Subject: [PATCH] patch --- src/ModelTrait.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/ModelTrait.php b/src/ModelTrait.php index 4af492b..dfa2a2e 100644 --- a/src/ModelTrait.php +++ b/src/ModelTrait.php @@ -106,6 +106,28 @@ public function setAttribute($key, $value) return parent::setAttribute($key, $value); } + /** + * @see \Illuminate\Database\Eloquent\Model + * + * @param string $key + * @return mixed + * @throws \Illuminate\Database\Eloquent\MissingAttributeException + */ + public function getAttribute($key) + { + if ( + ! \App::isProduction() + && $this->exists + && ! $this->wasRecentlyCreated + && array_key_exists($key, $this->casts) + && ! array_key_exists($key, $this->attributes) + ) { + throw new \Illuminate\Database\Eloquent\MissingAttributeException($this, $key); + } + + return parent::getAttribute($key); + } + /** * @see \Illuminate\Database\Eloquent\Concerns\HasAttributes::asJson() *