Transfer in our system are two well-known Deposit and Withdraw operations that are performed in one transaction.
The transfer takes place between wallets.
$transfer = $user1->transfer(
$user2,
511,
new Extra(
deposit: [
'type' => 'extra-deposit',
],
withdraw: new Option(
[
'type' => 'extra-withdraw',
],
false // confirmed
),
extra: [
'msg' => 'hello world',
],
)
);
Find user:
$first = User::first();
$last = User::orderBy('id', 'desc')->first(); // last user
$first->getKey() !== $last->getKey(); // true
As the user uses HasWallet, he will have balance property.
Check the user's balance.
$first->balance; // 100
$last->balance; // 0
The transfer will be from the first user to the second.
$first->transfer($last, 5);
$first->balance; // 95
$last->balance; // 5
It's simple!
Check the user's balance.
$first->balance; // 100
$last->balance; // 0
The transfer will be from the first user to the second.
$first->forceTransfer($last, 500);
$first->balance; // -400
$last->balance; // 500
It's simple!
How can I help you explore Laravel packages today?