From f1ef072b27c904070189d4968dbf529e545949e3 Mon Sep 17 00:00:00 2001 From: Aniket Das Date: Fri, 27 May 2022 03:47:09 +0530 Subject: [PATCH] `amount` field added to the `wallet_transactions` table --- .../migrations/create_wallet_transactions_table.php.stub | 5 +++-- src/Models/Wallet.php | 2 ++ src/Models/WalletTransaction.php | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/database/migrations/create_wallet_transactions_table.php.stub b/database/migrations/create_wallet_transactions_table.php.stub index 3cefb0a..d096ae5 100644 --- a/database/migrations/create_wallet_transactions_table.php.stub +++ b/database/migrations/create_wallet_transactions_table.php.stub @@ -13,8 +13,9 @@ return new class extends Migration $table->id(); $table->foreignIdFor(Wallet::class); $table->enum('type', ['credit', 'debit']); - $table->decimal('ob', 10, 2); - $table->decimal('cb', 10, 2); + $table->float('ob', 10, 2); + $table->float('cb', 10, 2); + $table->float('amount', 10, 2); $table->text('description'); $table->timestamps(); }); diff --git a/src/Models/Wallet.php b/src/Models/Wallet.php index 773c620..13aaa5f 100644 --- a/src/Models/Wallet.php +++ b/src/Models/Wallet.php @@ -49,6 +49,7 @@ public function deposit(int $amount, string $description) return $this->transactions()->create([ ...$transaction, 'type' => 'credit', + 'amount' => $amount, 'cb' => $this->balance, 'description' => $description, ]); @@ -82,6 +83,7 @@ public function withdraw(int $amount, string $description, bool $force = false) return $this->transactions()->create([ ...$transaction, 'type' => 'debit', + 'amount' => $amount, 'cb' => $this->balance, 'description' => $description, ]); diff --git a/src/Models/WalletTransaction.php b/src/Models/WalletTransaction.php index b0e5bec..44f94fd 100644 --- a/src/Models/WalletTransaction.php +++ b/src/Models/WalletTransaction.php @@ -10,6 +10,7 @@ class WalletTransaction extends Model use HasFactory; protected $fillable = [ + 'amount', 'ob', 'cb', 'description', @@ -19,6 +20,7 @@ class WalletTransaction extends Model protected $casts = [ 'ob' => 'float', 'cb' => 'float', + 'amount' => 'float', ]; public function wallet()