Refactor models.

This commit is contained in:
James Cole
2025-09-14 09:00:01 +02:00
parent 935453796e
commit 9d9483e20f
46 changed files with 688 additions and 676 deletions

View File

@@ -44,14 +44,13 @@ class TransactionJournalLink extends Model
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$linkId = (int) $value;
$linkId = (int)$value;
$link = self::where('journal_links.id', $linkId)
->leftJoin('transaction_journals as t_a', 't_a.id', '=', 'source_id')
->leftJoin('transaction_journals as t_b', 't_b.id', '=', 'destination_id')
->where('t_a.user_id', auth()->user()->id)
->where('t_b.user_id', auth()->user()->id)
->first(['journal_links.*'])
;
->leftJoin('transaction_journals as t_a', 't_a.id', '=', 'source_id')
->leftJoin('transaction_journals as t_b', 't_b.id', '=', 'destination_id')
->where('t_a.user_id', auth()->user()->id)
->where('t_b.user_id', auth()->user()->id)
->first(['journal_links.*']);
if (null !== $link) {
return $link;
}
@@ -83,27 +82,6 @@ class TransactionJournalLink extends Model
return $this->belongsTo(TransactionJournal::class, 'source_id');
}
protected function destinationId(): Attribute
{
return Attribute::make(
get: static fn ($value) => (int) $value,
);
}
protected function linkTypeId(): Attribute
{
return Attribute::make(
get: static fn ($value) => (int) $value,
);
}
protected function sourceId(): Attribute
{
return Attribute::make(
get: static fn ($value) => (int) $value,
);
}
protected function casts(): array
{
return [
@@ -111,4 +89,25 @@ class TransactionJournalLink extends Model
'updated_at' => 'datetime',
];
}
protected function destinationId(): Attribute
{
return Attribute::make(
get: static fn($value) => (int)$value,
);
}
protected function linkTypeId(): Attribute
{
return Attribute::make(
get: static fn($value) => (int)$value,
);
}
protected function sourceId(): Attribute
{
return Attribute::make(
get: static fn($value) => (int)$value,
);
}
}