Skip to content

Commit

Permalink
fix: removed old style details mutators. added new style.
Browse files Browse the repository at this point in the history
  • Loading branch information
h22k committed Dec 17, 2024
1 parent cb56948 commit 1efb78d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/Models/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1efb78d

Please sign in to comment.