PHPackages                             ifnot/statistics - 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. ifnot/statistics

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

ifnot/statistics
================

Tools for extracting statistics from a sql table

1.0(8y ago)125185[1 issues](https://github.com/IfnotFr/statistics/issues)WTFPLPHP

Since Mar 13Pushed 4y ago2 watchersCompare

[ Source](https://github.com/IfnotFr/statistics)[ Packagist](https://packagist.org/packages/ifnot/statistics)[ RSS](/packages/ifnot-statistics/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Statistics
==========

[](#statistics)

Allows you to extract a `Illuminate\Support\Collection` of statistics about a set of dated `Eloquent` rows.

Features
--------

[](#features)

- **Based on Carbon** : for easy date management and for an easy integration with `Eloquent`
- **A simple Cache** : for avoiding useless dupliated database queries
- **Custom interval and steps** : allows you to change dates (start, end) and the steps (yearly, monthly, daily, hourly)
- **Return a Collection** : a `Illuminate\Support\Collection` is returned for a simpler statistics handling
- **Indicator based** : for a simple and comprehensive way of querying statistics datas

Installation
------------

[](#installation)

Install it with composer :

composer require ifnot/statistics

Usage
-----

[](#usage)

### 1 : Instanciate a `Statistics` object from a eloquent query :

[](#1--instanciate-a-statistics-object-from-a-eloquent-query-)

```
use Ifnot\Statistics\Statistics;

// Get all validated sales (you can also take all with Sale::query())
$validSales = Sale::whereNotNull('validated_at');

// Put our sales into a Statistics object
$statistics = Statistics::of($validSales);
```

### 2 : Specify the date column and the interval for filtering datas :

[](#2--specify-the-date-column-and-the-interval-for-filtering-datas-)

```
use Ifnot\Statistics\Interval;

// If we want to build statistics about validation date of sales (it can be also of the creation date,
// in this case we will use the eloquent created_at ...)
$statistics->date('validated_at');

// Set the interval, the params :
// 1 : the interval, check the constants Interval::$DAILY, Interval::$MONTHLY etc ... or use the string "daily", "monthly" instead
// 2 : the start date with carbon
// 3 : the end date with carbon
$statistics->interval(Interval::$DAILY, Carbon::createFromFormat('Y-m-d', '2016-01-01'), Carbon::now())
```

### 3 : Add indicators :

[](#3--add-indicators-)

```
// We want to count the sales with shipping and without shipping
$statistics->indicator('with_shipping', function($row) {
 return $row->shipping ? 1 : 0;
});
$statistics->indicator('without_shipping', function($row) {
 return $row->shipping ? 0 : 1;
});

// And count the sales with more than 500.00 € amount
$statistics->indicator('expensive_bough', function($row) {
 if($row->amount > 500.00) {
  return 1;
 } else {
  return 0;
 }
});
```

### 4 : Handle datas :

[](#4--handle-datas-)

```
$collection = $statistics->make();

// Use a foreach if you want to loop on each dates
foreach($collection as $date => $values) {
 echo $date ' : ' . $values->expensive_bough;
}

// Use Collection methods for statistics
$collection->sum('with_shipping'); // Count the shipping
$collection->avg('with_shipping'); // Average shpping sales on each days on the interval (if you selected daily)
$collection->min('with_shipping'); // Minimum daily shipping on the interval
$collection->max('with_shipping');

// etc ...
```

Full Documentation
------------------

[](#full-documentation)

... Work here

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 90.5% 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2988d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/60343765?v=4)[ifnot](/maintainers/ifnot)[@ifnot](https://github.com/ifnot)

---

Top Contributors

[![IfnotFr](https://avatars.githubusercontent.com/u/1242308?v=4)](https://github.com/IfnotFr "IfnotFr (19 commits)")[![Teeqz](https://avatars.githubusercontent.com/u/82207672?v=4)](https://github.com/Teeqz "Teeqz (2 commits)")

### Embed Badge

![Health badge](/badges/ifnot-statistics/health.svg)

```
[![Health](https://phpackages.com/badges/ifnot-statistics/health.svg)](https://phpackages.com/packages/ifnot-statistics)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[jerome/filterable

Streamline dynamic Eloquent query filtering with seamless API request integration and advanced caching strategies.

19226.1k](/packages/jerome-filterable)[mnabialek/laravel-sql-logger

Log SQL queries in Laravel/Lumen framework

158796.3k2](/packages/mnabialek-laravel-sql-logger)[alajusticia/laravel-expirable

Make Eloquent models expirable

2193.4k5](/packages/alajusticia-laravel-expirable)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)

PHPackages © 2026

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