1. Go to this page and download the library: Download huoxin/money-with-history library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
huoxin / money-with-history example snippets
use Huoxin\MoneyWithHistory\Service\BalanceManager;
$this->connection->transaction(function () use ($user, $actor) {
$lockedUser = User::query()->whereKey($user->id)->lockForUpdate()->first();
// Your domain field
$lockedUser->last_checkin_time = now();
// Mutates $lockedUser->money on the model — does NOT save or write history yet
$this->balances->applyBalanceChange(
$lockedUser,
5.0,
'DAILY_CHECKIN_REWARD',
'vendor-my-extension.forum.history.checkin-reward',
['streakDays' => 7],
$actor
);
// One save persists both last_checkin_time AND money atomically.
// The afterSave callback then writes the history row and dispatches MoneyUpdated.
$lockedUser->save();
});
use Huoxin\MoneyWithHistory\Service\BalanceManager;
if ($this->extensions->isEnabled('huoxin-money-with-history')) {
$balanceManager = $this->container->make(BalanceManager::class);
$balanceManager->applyBalanceChange(...);
}
sh
composer migrate
php flarum cache:clear
sh
composer update huoxin/money-with-history
php flarum migrate
php flarum cache:clear