Skip to content

Commit 57e1d21

Browse files
author
Babichev Maxim
committed
Added default values to avoid upgrade errors
1 parent 7480cab commit 57e1d21

File tree

8 files changed

+31
-29
lines changed

8 files changed

+31
-29
lines changed

src/Commands/RefreshBalance.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function handle(): void
3939
{
4040
app(ProxyService::class)->fresh();
4141
app(DbService::class)->transaction(function () {
42-
$wallet = config('wallet.wallet.table');
42+
$wallet = config('wallet.wallet.table', 'wallets');
4343
app(DbService::class)
4444
->connection()
4545
->table($wallet)
@@ -72,8 +72,8 @@ protected function sqliteUpdate(): void
7272
*/
7373
protected function multiUpdate(): void
7474
{
75-
$wallet = config('wallet.wallet.table');
76-
$trans = config('wallet.transaction.table');
75+
$wallet = config('wallet.wallet.table', 'wallets');
76+
$trans = config('wallet.transaction.table', 'transactions');
7777
$availableBalance = app(DbService::class)
7878
->connection()
7979
->table($trans)

src/Models/Transaction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Transaction extends Model
5858
public function getTable(): string
5959
{
6060
if (!$this->table) {
61-
$this->table = config('wallet.transaction.table');
61+
$this->table = config('wallet.transaction.table', 'transactions');
6262
}
6363

6464
return parent::getTable();
@@ -77,7 +77,7 @@ public function payable(): MorphTo
7777
*/
7878
public function wallet(): BelongsTo
7979
{
80-
return $this->belongsTo(config('wallet.wallet.model'));
80+
return $this->belongsTo(config('wallet.wallet.model', WalletModel::class));
8181
}
8282

8383
}

src/Models/Transfer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Transfer extends Model
5454
public function getTable(): string
5555
{
5656
if (!$this->table) {
57-
$this->table = config('wallet.transfer.table');
57+
$this->table = config('wallet.transfer.table', 'transfers');
5858
}
5959

6060
return parent::getTable();

src/Models/Wallet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Wallet extends Model implements Customer, WalletFloat, Confirmable, Exchan
6464
public function getTable(): string
6565
{
6666
if (!$this->table) {
67-
$this->table = config('wallet.wallet.table');
67+
$this->table = config('wallet.wallet.table', 'wallets');
6868
}
6969

7070
return parent::getTable();

src/Traits/HasWallet.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function getBalanceAttribute(): int
8585
public function transactions(): MorphMany
8686
{
8787
return ($this instanceof WalletModel ? $this->holder : $this)
88-
->morphMany(config('wallet.transaction.model'), 'payable');
88+
->morphMany(config('wallet.transaction.model', Transaction::class), 'payable');
8989
}
9090

9191
/**
@@ -202,7 +202,7 @@ public function transfers(): MorphMany
202202
{
203203
return app(WalletService::class)
204204
->getWallet($this, false)
205-
->morphMany(config('wallet.transfer.model'), 'from');
205+
->morphMany(config('wallet.transfer.model', Transfer::class), 'from');
206206
}
207207

208208
}

src/Traits/HasWallets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function getWallet(string $slug): ?WalletModel
7474
*/
7575
public function wallets(): MorphMany
7676
{
77-
return $this->morphMany(config('wallet.wallet.model'), 'holder');
77+
return $this->morphMany(config('wallet.wallet.model', WalletModel::class), 'holder');
7878
}
7979

8080
/**

src/Traits/MorphOneWallet.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ trait MorphOneWallet
2222
public function wallet(): MorphOne
2323
{
2424
return ($this instanceof WalletModel ? $this->holder : $this)
25-
->morphOne(config('wallet.wallet.model'), 'holder')
26-
->where('slug', config('wallet.wallet.default.slug'))
25+
->morphOne(config('wallet.wallet.model', WalletModel::class), 'holder')
26+
->where('slug', config('wallet.wallet.default.slug', 'default'))
2727
->withDefault([
28-
'name' => config('wallet.wallet.default.name'),
29-
'slug' => config('wallet.wallet.default.slug'),
28+
'name' => config('wallet.wallet.default.name', 'Default Wallet'),
29+
'slug' => config('wallet.wallet.default.slug', 'default'),
3030
'balance' => 0,
3131
]);
3232
}

src/WalletServiceProvider.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Bavix\Wallet\Services\LockService;
1919
use Bavix\Wallet\Services\ProxyService;
2020
use Bavix\Wallet\Services\WalletService;
21+
use Bavix\Wallet\Simple\Rate;
22+
use Bavix\Wallet\Simple\Store;
2123
use Illuminate\Support\ServiceProvider;
2224
use function config;
2325
use function dirname;
@@ -83,25 +85,25 @@ public function register(): void
8385
);
8486

8587
// Bind eloquent models to IoC container
86-
$this->app->singleton(Rateable::class, config('wallet.package.rateable'));
87-
$this->app->singleton(Storable::class, config('wallet.package.storable'));
88-
$this->app->singleton(DbService::class, config('wallet.services.db'));
89-
$this->app->singleton(ExchangeService::class, config('wallet.services.exchange'));
90-
$this->app->singleton(CommonService::class, config('wallet.services.common'));
91-
$this->app->singleton(ProxyService::class, config('wallet.services.proxy'));
92-
$this->app->singleton(WalletService::class, config('wallet.services.wallet'));
93-
$this->app->singleton(LockService::class, config('wallet.services.lock'));
88+
$this->app->singleton(Rateable::class, config('wallet.package.rateable', Rate::class));
89+
$this->app->singleton(Storable::class, config('wallet.package.storable', Store::class));
90+
$this->app->singleton(DbService::class, config('wallet.services.db', DbService::class));
91+
$this->app->singleton(ExchangeService::class, config('wallet.services.exchange', ExchangeService::class));
92+
$this->app->singleton(CommonService::class, config('wallet.services.common', CommonService::class));
93+
$this->app->singleton(ProxyService::class, config('wallet.services.proxy', ProxyService::class));
94+
$this->app->singleton(WalletService::class, config('wallet.services.wallet', WalletService::class));
95+
$this->app->singleton(LockService::class, config('wallet.services.lock', LockService::class));
9496

9597
// models
96-
$this->app->bind(Transaction::class, config('wallet.transaction.model'));
97-
$this->app->bind(Transfer::class, config('wallet.transfer.model'));
98-
$this->app->bind(Wallet::class, config('wallet.wallet.model'));
98+
$this->app->bind(Transaction::class, config('wallet.transaction.model', Transaction::class));
99+
$this->app->bind(Transfer::class, config('wallet.transfer.model', Transfer::class));
100+
$this->app->bind(Wallet::class, config('wallet.wallet.model', Wallet::class));
99101

100102
// object's
101-
$this->app->bind(Bring::class, config('wallet.objects.bring'));
102-
$this->app->bind(Cart::class, config('wallet.objects.cart'));
103-
$this->app->bind(EmptyLock::class, config('wallet.objects.emptyLock'));
104-
$this->app->bind(Operation::class, config('wallet.objects.operation'));
103+
$this->app->bind(Bring::class, config('wallet.objects.bring', Bring::class));
104+
$this->app->bind(Cart::class, config('wallet.objects.cart', Cart::class));
105+
$this->app->bind(EmptyLock::class, config('wallet.objects.emptyLock', EmptyLock::class));
106+
$this->app->bind(Operation::class, config('wallet.objects.operation', Operation::class));
105107
}
106108

107109
}

0 commit comments

Comments
 (0)