whilesmart / eloquent-transactions
Account transactions (deposits, withdrawals, transfers, fees, adjustments) recorded against an account for Laravel applications, scoped per owner.
Package info
github.com/whilesmartphp/eloquent-transactions
pkg:composer/whilesmart/eloquent-transactions
Requires
- php: ^8.2
- laravel/framework: ^11.0|^12.0
- whilesmart/eloquent-owner-access: ^1.0
Requires (Dev)
- fakerphp/faker: ^1.24
- laravel/pint: ^1.22
- orchestra/testbench: ^9.0|^10.0
Suggests
- whilesmart/eloquent-accounts: Feeds account balances from posted transactions.
This package is auto-updated.
Last update: 2026-08-17 23:39:25 UTC
README
Account transactions for Laravel: deposits, withdrawals, transfers, fees, and adjustments recorded against an account and scoped per owner. It is the primitive for bare money movements that are not invoice payments or categorized expenses.
This is a movement primitive, not an accounting model. How balances are derived and whether the system is single- or double-entry is decided by the accounts/ledger layer that composes it; the same transactions can feed either.
Install
composer require whilesmart/eloquent-transactions
Migrations register automatically. Publish them to customize:
php artisan vendor:publish --tag=transactions-migrations php artisan vendor:publish --tag=transactions-config
Model
A Transaction belongs to a polymorphic owner and targets a polymorphic account. Each carries a type, a direction (credit adds, debit subtracts), a positive amount_cents, and a status. Only posted transactions should count toward a balance.
type:deposit,withdrawal,transfer,fee,adjustmentdirection:credit,debit(defaulted from the type when omitted)status:pending,posted,voidsignedAmountCents(): the amount signed by direction
Add Whilesmart\Transactions\Traits\HasTransactions to an owner model for a transactions() relation.
Endpoints
| Method | Path | Purpose |
|---|---|---|
| GET | /api/transactions |
List, filterable by owner, account, type, status, date range, and q |
| POST | /api/transactions |
Record a deposit, withdrawal, fee, or adjustment |
| GET | /api/transactions/{transaction} |
Show |
| PUT | /api/transactions/{transaction} |
Edit memo, counterparty, date, status, metadata |
| DELETE | /api/transactions/{transaction} |
Soft delete |
| POST | /api/transactions/transfer |
Move funds between two accounts as two matched legs |
| POST | /api/transactions/{transaction}/void |
Void a transaction (a transfer voids both legs) |
Authorization
Every request is scoped through whilesmart/eloquent-owner-access. The host binds an OwnerAuthorizer; the package never references an application user model.
Feeding account balances
When a transaction is written, TransactionRecorded fires with the transaction. Bridge it in the host to refresh the affected account (and, for a transfer, the counter account). whilesmart/eloquent-accounts sums posted transaction credits and debits into its computed balance.
Testing
composer test
composer pint:test