From 1efb78de8427d1b19ba0ebcac5783cfd1b781efb Mon Sep 17 00:00:00 2001 From: Halil Hakan Karabay Date: Tue, 17 Dec 2024 20:35:51 +0300 Subject: [PATCH] fix: removed old style details mutators. added new style. --- src/Models/DataType.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Models/DataType.php b/src/Models/DataType.php index 3165e8b5c5..6806310d5d 100644 --- a/src/Models/DataType.php +++ b/src/Models/DataType.php @@ -2,6 +2,7 @@ namespace TCG\Voyager\Models; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; @@ -247,16 +248,13 @@ public function extraFields() } } - public function setDetailsAttribute($value) + public function details(): Attribute { - $this->attributes['details'] = json_encode($value); + return new Attribute( + get: fn($value) => json_decode(!empty($value) ? $value : '{}', false, 512, JSON_THROW_ON_ERROR), + set: fn($value) => json_encode($value, JSON_THROW_ON_ERROR) + ); } - - public function getDetailsAttribute($value) - { - return json_decode(!empty($value) ? $value : '{}'); - } - public function getOrderColumnAttribute() { return $this->details->order_column ?? null;