mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Refactor models.
This commit is contained in:
@@ -28,7 +28,6 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
use function Safe\json_decode;
|
||||
use function Safe\json_encode;
|
||||
|
||||
@@ -39,29 +38,13 @@ class TransactionJournalMeta extends Model
|
||||
|
||||
protected $fillable = ['transaction_journal_id', 'name', 'data', 'hash'];
|
||||
|
||||
protected $table = 'journal_meta';
|
||||
|
||||
protected function data(): Attribute
|
||||
{
|
||||
return Attribute::make(get: fn ($value) => json_decode((string) $value, false), set: function ($value) {
|
||||
$data = json_encode($value);
|
||||
|
||||
return ['data' => $data, 'hash' => hash('sha256', $data)];
|
||||
});
|
||||
}
|
||||
protected $table = 'journal_meta';
|
||||
|
||||
public function transactionJournal(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(TransactionJournal::class);
|
||||
}
|
||||
|
||||
protected function transactionJournalId(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: static fn ($value) => (int) $value,
|
||||
);
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
@@ -70,4 +53,20 @@ class TransactionJournalMeta extends Model
|
||||
'deleted_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
protected function data(): Attribute
|
||||
{
|
||||
return Attribute::make(get: fn($value) => json_decode((string)$value, false), set: function ($value) {
|
||||
$data = json_encode($value);
|
||||
|
||||
return ['data' => $data, 'hash' => hash('sha256', $data)];
|
||||
});
|
||||
}
|
||||
|
||||
protected function transactionJournalId(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: static fn($value) => (int)$value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user