diff --git a/app/Models/TorrentExtra.php b/app/Models/TorrentExtra.php index c6551953..74477536 100644 --- a/app/Models/TorrentExtra.php +++ b/app/Models/TorrentExtra.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Casts\Attribute; use Nexus\Database\NexusDB; use Nexus\Torrent\TechnicalInformation; @@ -11,9 +12,23 @@ class TorrentExtra extends NexusModel protected $fillable = ['torrent_id', 'descr', 'ori_descr', 'media_info', 'nfo', 'pt_gen']; - protected $casts = [ - 'pt_gen' => 'array', - ]; + protected function ptGen(): Attribute + { + return Attribute::make( + get: function ($value) { + $jsonDecoded = json_decode($value, true); + if (is_array($jsonDecoded)) { + return $jsonDecoded; + } else { + return $value; + } + }, + set: function ($value) { + return is_array($value) ? json_encode($value) : $value; + } + ); + } + public function torrent() {