From b7712f7e6835d182f4fe9db0c054a7ebeaa3e45e Mon Sep 17 00:00:00 2001 From: George Klincarski <g.klincarski@gmail.com> Date: Tue, 23 Jan 2024 12:21:50 +0100 Subject: [PATCH 1/3] Update Transfer.php Model Update Transfer model to support dynamic loading of overwritten Wallet or Transaction model classes. Defaults to current Wallet and Transaction model from inside the package if no overwritten models specified. Signed-off-by: George Klincarski <g.klincarski@gmail.com> --- src/Models/Transfer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Models/Transfer.php b/src/Models/Transfer.php index 0d43bd422..89f23444b 100644 --- a/src/Models/Transfer.php +++ b/src/Models/Transfer.php @@ -81,7 +81,7 @@ public function getTable(): string */ public function from(): BelongsTo { - return $this->belongsTo(Wallet::class, 'from_id'); + return $this->belongsTo(config('wallet.wallet.model', Wallet::class), 'from_id'); } /** @@ -89,7 +89,7 @@ public function from(): BelongsTo */ public function to(): BelongsTo { - return $this->belongsTo(Wallet::class, 'to_id'); + return $this->belongsTo(config('wallet.wallet.model', Wallet::class), 'to_id'); } /** @@ -97,7 +97,7 @@ public function to(): BelongsTo */ public function deposit(): BelongsTo { - return $this->belongsTo(Transaction::class, 'deposit_id'); + return $this->belongsTo(config('wallet.transaction.model', Transaction::class), 'deposit_id'); } /** @@ -105,6 +105,6 @@ public function deposit(): BelongsTo */ public function withdraw(): BelongsTo { - return $this->belongsTo(Transaction::class, 'withdraw_id'); + return $this->belongsTo(config('wallet.transaction.model', Transaction::class), 'withdraw_id'); } } From 53e1ed95bc1b9cf174fd5a82172ad68845eb91a9 Mon Sep 17 00:00:00 2001 From: George Klincarski <g.klincarski@gmail.com> Date: Tue, 23 Jan 2024 13:41:30 +0100 Subject: [PATCH 2/3] Update Transfer Model Morph Transfer model has `from` and `to` relationships that actually morphed in the database. This change reflects that on the model too. Signed-off-by: George Klincarski <g.klincarski@gmail.com> --- src/Models/Transfer.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Models/Transfer.php b/src/Models/Transfer.php index 89f23444b..aa13882a6 100644 --- a/src/Models/Transfer.php +++ b/src/Models/Transfer.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\MorphTo; use function config; /** @@ -79,17 +80,17 @@ public function getTable(): string /** * @return BelongsTo<Wallet, self> */ - public function from(): BelongsTo + public function from(): MorphTo { - return $this->belongsTo(config('wallet.wallet.model', Wallet::class), 'from_id'); + return $this->morphTo(); } /** * @return BelongsTo<Wallet, self> */ - public function to(): BelongsTo + public function to(): MorphTo { - return $this->belongsTo(config('wallet.wallet.model', Wallet::class), 'to_id'); + return $this->morphTo(); } /** From c4cad87cbd6f8c7a84bf21338baad27fd980a65e Mon Sep 17 00:00:00 2001 From: George Klincarski <g.klincarski@gmail.com> Date: Tue, 23 Jan 2024 20:20:45 +0100 Subject: [PATCH 3/3] Revert MorphTo into BelongsTo Signed-off-by: George Klincarski <g.klincarski@gmail.com> --- src/Models/Transfer.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Models/Transfer.php b/src/Models/Transfer.php index aa13882a6..89f23444b 100644 --- a/src/Models/Transfer.php +++ b/src/Models/Transfer.php @@ -6,7 +6,6 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Database\Eloquent\Relations\MorphTo; use function config; /** @@ -80,17 +79,17 @@ public function getTable(): string /** * @return BelongsTo<Wallet, self> */ - public function from(): MorphTo + public function from(): BelongsTo { - return $this->morphTo(); + return $this->belongsTo(config('wallet.wallet.model', Wallet::class), 'from_id'); } /** * @return BelongsTo<Wallet, self> */ - public function to(): MorphTo + public function to(): BelongsTo { - return $this->morphTo(); + return $this->belongsTo(config('wallet.wallet.model', Wallet::class), 'to_id'); } /**