---
title: "Reading balances — Credits for Laravel | Roundly"
description: "Read the current or a past balance, check available credits with hasCredits(), and query the ledger relation directly."
url: https://roundly-consulting.com/open-source/docs/credits-for-laravel/balances
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)

# Reading balances

balance() sums the ledger rows of one bucket. Pass a point in time to reconstruct the balance as it stood then — only rows with created\_at at or before that moment count. has() compares the balance with an amount, 1 by default:

```php
Credits::for($user)->balance();                                // 70 — the default bucket
Credits::for($user)->balance(now()->subWeek());                // as of a point in time
Credits::for($user)->bucket('promotional')->balance(now()->startOfMonth());

Credits::for($user)->has(100);                                 // true if balance >= 100
Credits::for($user)->bucket('purchased')->has(100, now()->subWeek());
```

The trait forms are creditsBalance() and hasCredits():

```php
$user->creditsBalance();                         // 70 — the default bucket

// Balance as of a point in time (rows with created_at <= $at):
$user->creditsBalance(now()->subWeek());
$user->creditsBalance(at: now()->startOfMonth(), bucket: 'promotional');
```

The point in time is an instant: a $at in any timezone is moved to app.timezone — the zone created\_at is stored in — before it is compared, at second precision like the stored column.

## Checking available credits

hasCredits() compares the balance with an amount — 1 by default — and accepts the same point-in-time and bucket arguments:

```php
$user->hasCredits();                             // true if balance >= 1
$user->hasCredits(100);                          // true if balance >= 100
$user->hasCredits(100, now()->subWeek());        // ... as of a week ago
$user->hasCredits(100, bucket: 'purchased');     // ... in one bucket
```

has() and hasCredits() are reads, not reservations. To spend safely, deduct() and let the overdraft guard decide under its locks.

## The ledger relation

credits() is a standard MorphMany relationship, so the underlying rows are a query away:

```php
$user->credits()->latest()->get();              // every ledger row, newest first
$user->credits()->deductions()->count();         // the model's query scopes work on the relation
$user->credits()->withTrashed()->get();          // include soft-deleted rows
```

Credit uses soft deletes. A deleted row stays in the table but no longer counts toward any balance, and it is hidden from the relation unless you ask for withTrashed().

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