bensampo / laravel-count-totals
Elegantly count totals
1.0
2019-05-23 18:48 UTC
Requires
- php: ~7.1
- illuminate/support: 5.8.*
Requires (Dev)
- laravel/framework: 5.8.*
- orchestra/testbench: 3.8.*
- phpunit/phpunit: 7.5.*
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-11-24 06:51:31 UTC
README
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:
$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'], ]);