baks-dev/users-profile-balance
BaksDev Profile Balance — пакет для управления балансом профилей пользователей. Установка через Composer, установка конфигурации и ресурсов командой baks:assets:install, поддержка миграций Doctrine и тестов PHPUnit. Требуется PHP 8.4+.
BalanceService), which can be injected into controllers, jobs, or commands. This aligns with Laravel’s dependency injection and SOLID principles, reducing coupling with other domains (e.g., payments, notifications).BalanceUpdated) for extensibility. This enables decoupled side effects (e.g., sending emails, updating analytics) without modifying core balance logic.profile_balances). Pre-integration steps must:
user_id).--dry-run to avoid production downtime.Balance::decrement()). These should replace custom balance logic in controllers, jobs, or commands.// Replace custom logic:
// $user->balance -= 10; $user->save();
// With:
Balance::decrement($user->id, 10);
baks:assets:install and baks:cache:clear, which must be added to composer.json scripts for automated setup. Verify these tools don’t conflict with existing Laravel console commands.phpunit --group=users-profile-balance mentioned), raising concerns about edge-case handling (e.g., concurrent updates, negative balances).UPGRADE.md if it exists.composer.lock post-install.reputation_points and premium_credits?.env or config files?DB::transaction(function () use ($user, $amount) {
Balance::decrement($user->id, $amount);
// Other operations...
});
post-install-cmd? Example: Does it require php artisan optimize or cache clearing?baks:assets:install command integrates with Laravel’s Artisan system. Ensure no command name conflicts (e.g., php artisan baks:assets:install vs. your custom baks:install).php.ini.Cache::remember("balance_{$userId}", now()->addHours(1), function () use ($userId) {
return Balance::get($userId);
});
BalanceUpdated), you can listen to them for side effects:
Event::listen(BalanceUpdated::class, function ($event) {
// Send notification, log analytics, etc.
});
php artisan schema:dump
composer.json with auto-scripts:
"scripts": {
"post-install-cmd": [
"@auto-scripts",
"baks:assets:install"
],
"post-update-cmd": [
"@auto-scripts"
]
}
composer update and verify migrations generate without errors.user_id in package migrations to profile_user_id if your table uses user_id for joins.user_id) if the package doesn’t include them.php artisan doctrine:migrations:diff --dry-run
BalanceService to Laravel’s container (if not auto-discovered). Example in config/app.php:
'providers' => [
BaksDev\Balance\BalanceServiceProvider::class,
],
// Before:
$user->balance -= 10;
$user->save();
// After:
Balance::decrement($user->id, 10);
php artisan test --group=users-profile-balance
public function test_balance_decrement_triggers_event()
{
Event::fake();
Balance::decrement(1, 10);
Event::assertDispatched(BalanceUpdated::class);
}
symfony/console version mismatches).php.ini:
extension=pdo_mysql
extension=bcmath
opcache.enable=1
How can I help you explore Laravel packages today?