From c7c82873118103cec121ec294cc7ecfbcf997e1b Mon Sep 17 00:00:00 2001 From: DariusIII Date: Wed, 3 Jul 2024 23:09:27 +0200 Subject: [PATCH] Fix missing settings data from site edit page (add back __get function) --- app/Models/Settings.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/Models/Settings.php b/app/Models/Settings.php index a8a4f6b23..21792ff58 100644 --- a/app/Models/Settings.php +++ b/app/Models/Settings.php @@ -109,6 +109,25 @@ class Settings extends Model protected static $settingsCollection; + /** + * Adapted from https://laravel.io/forum/01-15-2016-overriding-eloquent-attributes. + * + * @return mixed + */ + public function __get($key) + { + $override = self::query()->where('name', $key)->first(); + + // If there's an override and no mutator has been explicitly defined on + // the model then use the override value + if ($override && ! $this->hasGetMutator($key)) { + return $override->value; + } + + // If the attribute is not overridden the use the usual __get() magic method + return parent::__get($key); + } + /** * Return a tree-like array of all or selected settings. *