change TorrentExtra.pt_gen setter/getter

This commit is contained in:
xiaomlove
2025-05-16 03:18:59 +07:00
parent d123e8a849
commit ac4515e1d8

View File

@@ -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()
{