Skip to content
No description, website, or topics provided.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.editorconfig
.gitignore
.travis.yml
LICENCE.txt
README.md
composer.json
phpunit.xml

README.md

About

Inspired by Jonathan Reinink's post about Calculating totals in Laravel using conditional aggregates I've created an elegant way to grab multiple totals in an efficient way.

Please see the post for details about what this package aims to solve.

Install

composer require bensampo/laravel-count-totals

Usage

Given the following subscribers table structure:

name status
Adam Campbell confirmed
Taylor Otwell confirmed
Jonathan Reinink bounced
Adam Wathan cancelled
$totals = Subscriber::countTotals([
    ['status' => 'confirmed'],
    ['status' => 'cancelled'],
    ['name' => 'Jonathan Reinink'],
]);

$totals->confirmed // 2
$totals->cancelled // 1
$totals->jonathanReinink // 1

You may also use the DB facade:

$totals = DB::table('subscribers')->countTotals([
    ['status' => 'confirmed'],
    ['status' => 'cancelled'],
    ['name' => 'Jonathan Reinink'],
]);
You can’t perform that action at this time.