mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
change TorrentExtra.pt_gen setter/getter
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user