---
title: "Events — Credits for Laravel | Roundly"
description: "React to every recorded change with the CreditsModified event — the owner, the new ledger row and the bucket’s new balance."
url: https://roundly-consulting.com/open-source/docs/credits-for-laravel/events
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Credits for Laravel](https://roundly-consulting.com/open-source/docs/credits-for-laravel.md)

# Events

RoundlyConsulting\\Credits\\Events\\CreditsModified is dispatched after every recorded change. It carries the creditable, the new Credit row and the resulting balance:

```php
use Illuminate\Support\Facades\Event;
use RoundlyConsulting\Credits\Events\CreditsModified;

Event::listen(function (CreditsModified $event): void {
    // $event->creditable, $event->credit, $event->balance
});
```

## Payload

```php
final class CreditsModified implements ShouldDispatchAfterCommit
{
    use Dispatchable;

    public function __construct(
        public readonly Model&Creditable $creditable,
        public readonly Credit $credit,
        public readonly int $balance,   // the bucket's balance this change produced
    ) {}
}
```

balance is the balance of the bucket that changed — read it from $event->credit->bucket — not a total across buckets. It is the balance this change produced, read under the owner lock inside the change’s transaction, so a racing change never leaks into it.

## When it fires

- After every successful write — add(), deduct(), modify(), setTo() and their Money forms on a scope, the matching trait methods — and for each entity credits:modify changes.
- Only once the change is committed: CreditsModified implements ShouldDispatchAfterCommit, so inside setTo() or your own DB::transaction() listeners receive it when the outermost transaction commits — and never for a change that is rolled back. A listener that throws cannot roll the change back; check before making the change instead.
- Not when setCreditsTo() is a no-op because the balance already matches.
- Not when the overdraft guard, the 64-bit bound or a money check refuses the change — nothing was written.

## A listener

Send a receipt, update a dashboard or alert on a low balance:

```php
use Illuminate\Support\Facades\Log;

Event::listen(function (CreditsModified $event): void {
    Log::info("Balance for {$event->creditable->getKey()} is now {$event->balance}");

    if ($event->credit->amount < 0 && $event->balance < 10) {
        // $event->credit->bucket is running low — notify the owner
    }
});
```

## 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 crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/credits-for-laravel.md)
