Skip to content

Commit 19fdce5

Browse files
committed
fix MorphOneWallet
1 parent a0fd6b3 commit 19fdce5

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/Traits/MorphOneWallet.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,23 @@ trait MorphOneWallet
2121
*/
2222
public function wallet(): MorphOne
2323
{
24-
return app(CastServiceInterface::class)
24+
$castService = app(CastServiceInterface::class);
25+
26+
return $castService
2527
->getHolder($this)
2628
->morphOne(config('wallet.wallet.model', WalletModel::class), 'holder')
2729
->where('slug', config('wallet.wallet.default.slug', 'default'))
28-
->withDefault(static function (WalletModel $wallet, object $holder) {
30+
->withDefault(static function (WalletModel $wallet, object $holder) use ($castService) {
31+
$model = $castService->getModel($holder);
2932
$wallet->forceFill(array_merge(config('wallet.wallet.creating', []), [
3033
'name' => config('wallet.wallet.default.name', 'Default Wallet'),
3134
'slug' => config('wallet.wallet.default.slug', 'default'),
3235
'meta' => config('wallet.wallet.default.meta', []),
3336
'balance' => 0,
3437
]));
3538

36-
if (property_exists($holder, 'exists') && $holder->exists) {
37-
$wallet->setRelation(
38-
'holder',
39-
method_exists($holder, 'withoutRelations')
40-
? $holder->withoutRelations()
41-
: $holder
42-
);
39+
if ($model->exists) {
40+
$wallet->setRelation('holder', $model->withoutRelations());
4341
}
4442
})
4543
;

0 commit comments

Comments
 (0)