All packages
Credits for Laravel
Artisan commands
credits:modify applies one credit change to every entity resolved by the credits.modifiable config, through Credits::for($entity) — so Credits::fake() records it. Register one or more resolver closures — each receives a $modify callback to call per entity:
// config/credits.php
use App\Models\User;
'modifiable' => [
function (Closure $modify): void {
User::query()->each(fn (User $user) => $modify($user));
},
],Then run it:
php artisan credits:modify --amount=10 --description="monthly bonus"
# Modified credits on 42 entities.
php artisan credits:modify --amount=50 --description="monthly bonus" --bucket=promotional
php artisan credits:modify --amount=-5 --description="correction" --allow-overdraft| Option | Default | Description |
|---|---|---|
--amount | 0 | The credit amount to apply. Must be an integer and may be negative; a non-integer value fails with a non-zero exit code. |
--description | null | An optional human-readable description stored on each row. |
--bucket | configured default | The named bucket to apply the change to. Omit to use default_bucket. |
--allow-overdraft | false | Permit deductions that drive the balance below minimum_balance (which may be other than zero). |
- Each row the command writes carries meta ['info' => 'Credits modified by credits:modify command.'].
- Resolved entities that are not Creditable models are skipped with a warning rather than failing the run.
- An entity whose deduction the overdraft guard refuses is skipped too: the run carries on with the rest and prints a Refused line for each.
- Once every entity has been visited, the command reports how many were refused and exits non-zero.
- Each change is its own transaction, so the entities that were charged stay charged — re-run only for the refused ones (for example with a resolver that selects them), not the whole set.
- With no resolvers registered, the command succeeds and changes nothing.
php artisan credits:modify --amount=-50 --description="monthly fee"
# Refused App\Models\User #2: Insufficient credits: tried to deduct 50 but only 20 are available.
# Modified credits on 41 entities.
# Refused 1 entity with insufficient credits.
echo $? # 1 — the run finished, but not every entity was chargedInspecting the configuration
The package contributes a section to Laravel’s about command:
php artisan about --only=credits| Row | Shows |
|---|---|
| Model | The resolved ledger model’s class name. |
| Primary key type | credits.primary_key_type — surfaced because a non-bigint id cannot be held by another package’s morphs() column on a strict engine. |
| Creditable key type | credits.key_type. |
| Overdraft | ALLOWED or BLOCKED — read from allow_overdraft as a boolean, the same way the guard reads it. |
| Minimum balance | credits.minimum_balance, or INVALID when the value is malformed — about keeps working. |
| Default bucket | credits.default_bucket, or INVALID when the value is malformed. |
| Scale | credits.scale, or INVALID when the value is malformed. |
| Rounding | The display rounding mode in its config spelling, or INVALID when credits.rounding names no mode. |
| Modifiable resolvers | NONE or “N registered” — a count, never what they resolve; INVALID when credits.modifiable is malformed. |
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.