From 09fb03a1cecef4f1291b0acac1e58830a4d3f0f6 Mon Sep 17 00:00:00 2001 From: xboard Date: Thu, 18 Apr 2024 01:27:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BD=93=20server=5Ft?= =?UTF-8?q?oken=20=E4=B8=BA=E9=95=BF=E6=95=B0=E5=AD=97=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E4=BC=9A=E8=BD=AC=E5=8C=96=E6=88=90=E7=A7=91?= =?UTF-8?q?=E5=AD=A6=E8=AE=A1=E6=95=B0=E6=B3=95=EF=BC=8C=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Setting.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 19abbbd..38e707a 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -7,25 +7,31 @@ use Illuminate\Database\Eloquent\Model; class Setting extends Model { protected $table = 'v2_settings'; - protected $guarded = []; + protected $guarded = []; + protected $casts = [ + 'key' => 'string', + 'value' => 'string', + ]; public function getValueAttribute($value) { if ($value === null) { - // 如果值为 null,你可能想要处理这种情况,例如返回一个默认值 - return null; // 或者返回你期望的默认值 + return null; } - if (!is_string($value)) { + + if (is_array($value)) { return $value; } - - $decodedValue = json_decode($value, true); + if (is_numeric($value) && !preg_match('/[^\d.]/', $value)) { + return $value; + } + + $decodedValue = json_decode($value, true); if (json_last_error() === JSON_ERROR_NONE) { return $decodedValue; } - // 如果不是有效的 JSON 数据,则保持为字符串 return $value; } }