Download the PHP package laratusk/cashflow without Composer

On this page you can find all versions of the php package laratusk/cashflow. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package cashflow

Cashflow

A double-entry balance transaction ledger for Laravel. Track credits, debits, fees, and derived amounts with type-safe balance items, validation, and dependency enforcement.

Installation

Publish the migration and run it:

Optionally publish the config (only needed if you want to override the BalanceTransaction model):

Quick Start

Setup

Add HasBalanceTransactions to any model that holds a balance:

This adds a balanceTransactions() morph-many relationship.

Why Balance Items Are Not Shipped

Cashflow does not ship any BalanceItem classes. Every business has different transaction types -- a SaaS platform has subscriptions and usage fees, a marketplace has commissions and payouts, a payment processor has gateway fees and dispute charges.

Balance items are your domain logic. The package provides the base class (BalanceItem), attributes (#[Unique], #[Rule], #[Requires]), and the Balance engine. You define the items that match your business.

Generating Balance Items

Use the artisan command to scaffold new items interactively:

The command asks:

  1. Class name -- e.g. Payment, GatewayFee, Refund
  2. Direction -- Debit or Credit
  3. Amount source -- Passed from outside, fixed value, or derived from another item
  4. Unique? -- Whether to add #[Unique]
  5. Requires? -- Dependency on another balance item

Files are created in app/Cashflow/BalanceItems/. Add validation rules directly in the generated class.

Defining Balance Items

Extend BalanceItem and define direction(). If the constructor has an $amount parameter, it is resolved automatically -- no need to override amount():

The base class auto-resolves $amount and $direction from constructor properties. Override amount() only when you need custom logic (derived amounts, fixed values).

Fixed vs Derived Amounts

Items can receive their amount directly or calculate it from siblings:

Implementation with required_without validation:

Override Protection

Multi-Currency Items

Override currency() and provide an exchange rate:

When an item's currency differs from the balance currency, an exchange rate other than 1.0 is required -- otherwise save() throws MissingExchangeRateException.

Attributes

#[Rule(...)]

Laravel validation rules for constructor parameters. Validated on insert(). Supports all Laravel rules including cross-field rules like required_without.

#[Unique]

One instance per reference morph. Inserting a duplicate throws DuplicateBalanceItemException. Checked against in-memory and DB items.

#[Requires(ClassName::class)]

Enforces dependency on another balance item. Repeatable. Checked against in-memory and DB items.

Metadata

Attach free-form data to any balance item. Stored as JSON, restored when loading from DB.

Reading metadata back:

Batch Operations

Every save() groups items under a single batch_id (UUID).

Reading from DB

Items loaded from DB are read-only BalanceItem instances with saved = true.

Uniqueness Scoping

Uniqueness is scoped per reference morph:

Real-World Examples

Stripe Payment

TrustPayment (Rate-Based)

Refund

Dispute with Evidence Fee

API Reference

Balance

Method Description
Balance::for(Model $balanceable) Create a new balance instance
->reference(Model $ref) Scope to a reference morph
->currency(string $currency) Set the balance currency (ISO 4217)
->insert(BalanceItem $item) Add an item to the batch
->save() Persist unsaved items in a DB transaction
->batchId() Get the batch UUID
->get() Load saved items from DB
->items() All items (saved + unsaved)
->saved() Only persisted items
->unsaved() Only pending items
->has(string $class) Check if an item key exists
->amountOf(string $class) Get amount of a specific item
Balance::dropBatch(string $id) Delete all transactions in a batch

BalanceItem

Method Default Override
key() FQCN Optional
amount() Auto-resolved from $amount property Override for derived/fixed amounts
direction() Auto-resolved from $direction property Override to hardcode direction
currency() null (uses balance currency) Optional
exchangeRate() 1.0 Optional
withMetadata(?array $data) Fluent setter --

Exceptions

Exception When
MissingCurrencyException No currency on balance or item
MissingExchangeRateException Different currency but rate is 1.0
DuplicateBalanceItemException #[Unique] item already exists
MissingRequiredBalanceItemException #[Requires] dependency missing
BatchAlreadySavedException save() or insert() after commit
EmptyBatchException save() with no unsaved items
BalanceItemNotFoundException amountOf() for missing key
BalanceNotSetException balance() called before insert()

Currency

Cashflow uses plain ISO 4217 strings ('USD', 'EUR', 'TRY') for currency codes. No currency enum is shipped -- use whichever currency library fits your project.

For validation, squirephp/currencies-en works well:

Database Schema

Column Type Notes
id bigint (PK) auto-increment
batch_id uuid indexed, groups items
balanceable_id bigint morph FK
balanceable_type string morph type
reference_id bigint/null morph FK
reference_type string/null morph type
direction string debit / credit
amount bigint unsigned minor units (cents)
currency string(3) ISO 4217
exchange_rate decimal(12,6) default 1.0
key string FQCN by default
metadata json/null free-form data
created_at timestamp auto-set

Configuration

Override the model to customize the table name, casts, or add behavior.

License

MIT


All versions of cashflow with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/validation Version ^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package laratusk/cashflow contains the following files

Loading the files please wait ...