'boolean', 'created_at' => 'datetime', 'updated_at' => 'datetime' ]; /** * The attributes that should be mutated to dates. * * @var array */ protected $dates = [ 'created_at', 'updated_at' ]; /** * Indicates if the model should be timestamped. * * @var bool */ public $timestamps = true; /** * Get the user who updated the config. */ public function updatedByUser(): BelongsTo { // Check if Auth module exists before relating if (class_exists('\Modules\Auth\Models\User')) { return $this->belongsTo(\Modules\Auth\Models\User::class, 'system_config_updated_by'); } // Fallback or return empty relation if Auth module is missing (unlikely but safe) return $this->belongsTo(self::class, 'system_config_updated_by')->whereNull('system_config_id'); } /** * Get config value by key. * * @param string $key * @param mixed $default * @return mixed */ public static function get(string $key, $default = null) { $config = self::where('system_config_key', $key)->first(); if (!$config) { return $default; } // Handle type casting if needed based on system_config_type // For now, return value directly return $config->system_config_value; } /** * Set config value. * * @param string $key * @param mixed $value * @param string $type * @param string|null $description * @param bool $isPublic * @return self */ public static function set(string $key, $value, string $type = 'string', ?string $description = null, bool $isPublic = false): self { $config = self::firstOrNew(['system_config_key' => $key]); $config->system_config_value = $value; $config->system_config_type = $type; if ($description !== null) { $config->system_config_description = $description; } $config->system_config_is_public = $isPublic; if (isset($_SESSION['user_id'])) { $config->system_config_updated_by = $_SESSION['user_id']; } $config->save(); return $config; } }