Download the PHP package openplain/laravel-flowfield without Composer

On this page you can find all versions of the php package openplain/laravel-flowfield. 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 laravel-flowfield

Laravel FlowField

Latest Version on Packagist Total Downloads

Cache-backed computed aggregate fields for Eloquent — inspired by Navision's FlowField concept.

Why This Package?

When your Customer model needs to show a balance (sum of all ledger entries), or your Item needs inventory_quantity (sum of stock movements), you have two bad options: run the aggregate query every time (slow with thousands of entries), or store a denormalized total and keep it in sync manually (fragile — things drift, you build a "recalc" button).

In the late 1980s, three Danish engineers at PC&C (later Navision, now Microsoft Business Central) solved this exact problem. Their answer was FlowFields — virtual fields that compute aggregates on demand without storing the result in the database. Navision defined seven FlowField types: Sum, Count, Average, Min, Max, Exist, and Lookup. For Sum fields specifically, they built SIFT (Sum Index Field Technology) — pre-calculated indexes maintained on every write to make sum lookups instant. This concept has powered millions of ERP installations for over 35 years.

We brought the FlowField concept to Laravel. Where Navision uses SIFT indexes for sums and live queries for the rest, we use your cache layer (Redis/Memcached) as the performance layer for all aggregate types.

Our Goal: Declare aggregate fields as model attributes. Computed once, cached in Redis/Memcached, automatically invalidated when data changes. Instant reads. Zero maintenance. No stale data.

Built on Proven Technology

Features

Requirements

Installation

Install via Composer:

Optionally publish the configuration file:

Quick Start

1. Define FlowFields on Your Parent Model

Add the HasFlowFields trait and use the #[FlowField] attribute on accessor methods:

2. Set Up Auto-Invalidation on Source Models

Add the InvalidatesFlowFields trait to models that contribute data:

3. Use It

Usage

Defining FlowFields

The #[FlowField] attribute accepts the following parameters:

Parameter Type Default Description
method string (required) Aggregate function: sum, count, avg, min, max, exists
relation string (required) Name of the Eloquent relationship method
column string '*' Column to aggregate
where array [] Static where conditions
ttl ?int null Cache TTL override in seconds
cacheKey ?string null Custom cache key suffix

All Aggregate Methods

Filtered Aggregates

Use the where parameter to aggregate a subset of records:

Automatic Invalidation

The InvalidatesFlowFields trait handles cache invalidation when source records are created, updated, deleted, or restored.

Smart invalidation: When a source record is updated, only FlowFields whose aggregated column or where-condition columns actually changed are invalidated. Updating an irrelevant column (like notes) won't bust the cache.

Foreign key changes: If a record moves from one parent to another (e.g., reassigning an order line), both the old and new parent's caches are invalidated.

Manual Calculation

Force-recalculate specific fields (equivalent to NAV's CALCFIELDS):

Flushing Cache

Eager Computation with withFlowFields

FlowFields are not auto-appended to toArray()/toJson() to avoid N+1 queries when serializing collections. Use the withFlowFields scope to compute them eagerly:

Sorting by FlowField

Sort query results by an aggregate value using a subquery:

Inspecting Definitions

Configuration

All settings are in config/flowfield.php. All are optional with sensible defaults.

Cache Store

Which cache store to use. Defaults to your application's default cache store.

Cache TTL

Cache lifetime in seconds. Defaults to null (forever) since invalidation is event-driven. Set a value like 3600 as a safety net if you have processes that bypass Eloquent events (raw SQL, external systems).

Note: Individual FlowFields can override this via the ttl attribute parameter.

Cache Key Prefix

Prefix for all FlowField cache keys. Useful to avoid collisions.

Auto-Warm

When enabled, the cache is immediately re-populated after invalidation instead of waiting for the next read.

Note: Enabling this adds a query on every write to source models. Only enable if read performance is critical.

Tag-Based Invalidation

Uses cache tags when the driver supports them (Redis, Memcached) for efficient bulk invalidation. Falls back to prefix-based key management for simpler drivers.

Artisan Commands

Warm Cache

Pre-populate FlowField caches:

Flush Cache

Clear cached FlowField values:

Real-World Use Cases

E-Commerce: Order Totals

SaaS: Subscription Metrics

Inventory: Stock Levels

Limitations

Inspiration

This package implements the FlowField concept from Microsoft Dynamics NAV/Business Central — virtual fields that display computed aggregates (Sum, Count, Average, Min, Max, Exist) without storing the result in the table.

The performance layer behind FlowFields has evolved over the decades:

We take a different approach: cache as the performance layer. Where Navision/Business Central relies on SQL Server features (indexed views, columnstore indexes), we use Redis or Memcached. The tradeoff is simplicity — no database schema changes, works with any database — at the cost of eventual consistency during the brief window between a write and cache invalidation.

For the curious:

Testing

Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

Security

If you discover a security vulnerability, please email [email protected]. All security vulnerabilities will be promptly addressed.

Please do not open public issues for security vulnerabilities.

License

The MIT License (MIT). Please see License File for more information.


Built with ❤️ by Openplain


All versions of laravel-flowfield with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/cache Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.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 openplain/laravel-flowfield contains the following files

Loading the files please wait ...