PHPackages                             whilesmart/eloquent-accounts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. whilesmart/eloquent-accounts

ActiveLibrary[Database &amp; ORM](/categories/database)

whilesmart/eloquent-accounts
============================

Polymorphic financial account records for Laravel: bank accounts, mobile money wallets, card processors, cash registers. Attachable to payments and expenses.

05PHP

Since Apr 24Pushed 1mo agoCompare

[ Source](https://github.com/whilesmartphp/eloquent-accounts)[ Packagist](https://packagist.org/packages/whilesmart/eloquent-accounts)[ RSS](/packages/whilesmart-eloquent-accounts/feed)WikiDiscussions dev Synced 1w ago

READMEChangelogDependenciesVersions (3)Used By (0)

Eloquent Accounts
=================

[](#eloquent-accounts)

Polymorphic financial account records for Laravel. Bank accounts, mobile money wallets, card processors, cash registers, crypto wallets. Attaches on the account side of `whilesmart/eloquent-payments` and `whilesmart/eloquent-expenses`.

Why
---

[](#why)

`eloquent-payments` and `eloquent-expenses` both carry a nullable `account` polymorph. Without a concrete account model those fields go unused; reporting can't answer "what's in the Lagos UBA account right now?" or "how much came in through MTN MoMo this month?"

This package fills that gap. It is optional: if you don't install it, the morph columns on payments / expenses stay null and nothing breaks.

Install
-------

[](#install)

```
composer require whilesmart/eloquent-accounts
php artisan migrate

```

Attach `HasAccounts` to the model that owns accounts (typically a workspace):

```
use Whilesmart\Accounts\Traits\HasAccounts;

class Workspace extends Model
{
    use HasAccounts;
}
```

Data model
----------

[](#data-model)

One `accounts` table. Each row belongs polymorphically to an owner and holds:

- **Identity**: `name`, `type` (`bank | mobile_money | card_processor | wallet | cash | crypto | other`), `status` (`active | closed | frozen`).
- **Provider**: `provider` (string, e.g. `UBA`, `MTN MoMo`, `Stripe`), `provider_reference`, `identifier` (account number / last 4 / wallet number, safe to display).
- **Money**: `currency`, `opening_balance_cents`, `balance_cents`.
- **`is_primary`**: default account for its owner + currency. Helper `primaryAccount(string $currency = null)` on the owner.
- **`metadata`**: JSON.

`type` and `provider` are free-form strings at the DB level so new rails don't need migrations; `AccountType` enum carries the canonical values.

Balance
-------

[](#balance)

Two modes:

1. **Computed** (default, `ACCOUNTS_COMPUTE_BALANCE=true`): when you read an account, `balance_cents` is derived as `opening_balance_cents + succeeded inbound payments - succeeded outbound payments - paid expenses`. Requires `whilesmart/eloquent-payments` and/or `whilesmart/eloquent-expenses`; gracefully degrades if they are not installed.
2. **Stored** (`ACCOUNTS_COMPUTE_BALANCE=false`): reads the `balance_cents` column. Call `$account->refreshBalance()` (or `POST /api/accounts/{id}/refresh-balance`) to recompute and persist.

Routes
------

[](#routes)

```
GET    /api/accounts
POST   /api/accounts
GET    /api/accounts/{account}
PUT    /api/accounts/{account}
DELETE /api/accounts/{account}
POST   /api/accounts/{account}/refresh-balance

```

Index filters: `owner_type`, `owner_id`, `type`, `status`, `currency`, `q`, `per_page`.

Config
------

[](#config)

`php artisan vendor:publish --tag=accounts-config`:

```
return [
    'register_routes' => env('ACCOUNTS_REGISTER_ROUTES', true),
    'route_prefix' => env('ACCOUNTS_ROUTE_PREFIX', 'api'),
    'route_middleware' => ['api', 'auth:sanctum'],
    'table' => env('ACCOUNTS_TABLE', 'accounts'),
    'compute_balance' => env('ACCOUNTS_COMPUTE_BALANCE', true),
];
```

Siblings
--------

[](#siblings)

- `whilesmart/eloquent-payments` -- inbound / outbound transfers. Each Payment has `account_type` + `account_id`.
- `whilesmart/eloquent-expenses` -- expenses, paid from accounts.
- `whilesmart/eloquent-invoices` -- invoices (money in). Tracks summary totals on the invoice row; actual payment records live in `eloquent-payments`, which reference an Account.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance60

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a1ca6f6e01ecbfe6640ff410c4f0321054fb48d05a5f843c2b89887b90369bcd?d=identicon)[whilesmart](/maintainers/whilesmart)

---

Top Contributors

[![nfebe](https://avatars.githubusercontent.com/u/14317775?v=4)](https://github.com/nfebe "nfebe (5 commits)")

### Embed Badge

![Health badge](/badges/whilesmart-eloquent-accounts/health.svg)

```
[![Health](https://phpackages.com/badges/whilesmart-eloquent-accounts/health.svg)](https://phpackages.com/packages/whilesmart-eloquent-accounts)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8361.6M87](/packages/propel-propel1)[mpociot/laravel-composite-key

Support composite keys in your laravel app.

3544.8k1](/packages/mpociot-laravel-composite-key)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
