Laravel Stats Helper

Overview

Laravel Stats Helper

Latest Stable Version MIT Licensed Quality Score Total Downloads GitHub Workflow Status

With laravel-stats-helper you can get the statistics of two values or an array of values. It allows you to get the difference, percentage, change in percentage and an indicator whether the change is positive or negative. This helper could be useful in generating simple graphs or statistics for a dashboard or reporting page.

Requirements

  • Laravel 8.x or 9.x

Laravel support

Version Release
9.x 1.1
8.x 1.0

Installation

Install the package via composer:

composer require label84/laravel-stats-helper

Usage

use Label84\StatsHelper\Facades\StatsHelper;

$stats = StatsHelper::init(40, 60);

$stats->getOld();                   // 40
$stats->getNew();                   // 60
$stats->getDifference();            // 20
$stats->getPercentage();            // 150
$stats->getChangeInPercentage();    // 50% (it's a 50% increase)
$stats->isPositive();               // true
$stats->isNegative();               // false

You can use the StatsArrayHelper to get the stats for multiple items.

use Label84\StatsHelper\Facades\StatsArrayHelper;

$colection = StatsArrayHelper::create([
    'January' => 10,
    'February' => 50,
    'March' => 75,
    'April' => 200,
    'May' => 100,
])
->mapWithKeys(fn ($stats, $key) => [$key => $stats->getChangeInPercentage().'%']);

// Illuminate\Support\Collection
'January' => '0%',                  // (no previous value available)
'February' => '400%',
'March' => '50%',
'April' => '167%',
'May' => '-50%',

You can also set new values with the setPrev and setNext methods. This could be helpful in a for/foreach loop.

use Label84\StatsHelper\Facades\StatsHelper;

$stats = StatsHelper::init(50, 60);

$stats->getDifference();            // 10

$stats->setNext(100);

$stats->getOld();                   // 60
$stats->getNew();                   // 100
$stats->getDifference();            // 10

Tests

./vendor/bin/phpstan analyze
./vendor/bin/phpunit

License

MIT

You might also like...
Laravel helper to generate the QRcode for ZATCA E-Invoicing system

Laravel-ZATCA Unofficial package to implement ZATCA QRcode for E-Invoicing. Requirements PHP = 7.4 An mbstring extension Dependencies chillerlan/php-

Laravel IDE Helper

Laravel IDE Helper Generator Complete PHPDocs, directly from the source This package generates helper files that enable your IDE to provide accurate a

Helper class for working with Laravel Mix in WordPress themes and plugins.

Hybrid\Mix Hybrid Mix is a class for working with Lavarel Mix. It adds helper methods for quickly grabbing asset files cached in the mix-manifest.json

A convenient helper for using the laravel-seo package with Filament Admin and Forms
A convenient helper for using the laravel-seo package with Filament Admin and Forms

Combine the power of Laravel SEO and Filament PHP. This package is a convenient helper for using the laravel-seo package with Filament Admin and Forms

Localization Helper - Package for convenient work with Laravel's localization features and fast language files generation
Localization Helper - Package for convenient work with Laravel's localization features and fast language files generation

Localization Helper Package for convenient work with Laravel's localization features and fast language files generation. Installation Via Composer $ c

:passport_control: Helper for Google's new noCAPTCHA (reCAPTCHA v2 & v3)
:passport_control: Helper for Google's new noCAPTCHA (reCAPTCHA v2 & v3)

noCAPTCHA (new reCAPTCHA) By ARCANEDEV© What is reCAPTCHA? reCAPTCHA is a free service that protects your site from spam and abuse. It uses advanced r

A collection of helper functions that I use across my projects.

A collection of helper functions that I use across my projects. This package includes some of the helper functions that I tend to use in all of my pro

SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization).

SEO Helper By ARCANEDEV© SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization). Feel free to check out the rele

Live Helper Chat - live support for your website. Featuring web and mobile apps, Voice & Video & ScreenShare. Supports Telegram, Twilio (whatsapp), Facebook messenger including building a bot.

Live helper chat It's an open-source powered application, which brings simplicity and usability in one place. With live helper chat you can bring live

Releases(v1.1.0)
Owner
Label84
Label84
A helper package to flash a bootstrap alert to the browser via a Facade or a helper function.

Alert Box (Laravel) A helper package to flash a bootstrap alert to the browser via a Facade or a helper function. <div class="alert alert-info fade in

Ben-Piet O'Callaghan 17 Dec 30, 2022
Cache-purge-helper - Additional instances where nginx-helper and lscache plugin should be purged.

cache-purge-helper Additional instances where nginx-helper and lscache plugin should be purged. Install Extract the zip file. Upload them to /wp-conte

Jordan 10 Oct 5, 2022
Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries

Laravel Query Helper Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries, this package will contain all advanced SQL

Syrian Open Source 15 Nov 20, 2022
The missing laravel helper that allows you to inspect your eloquent queries with it's bind parameters

Laravel Query Inspector The missing laravel helper that allows you to ispect your eloquent queries with it's bind parameters Motivations Let's say you

Mouad ZIANI 59 Sep 25, 2022
Laravel-Mix helper for projects with complex & multi assets.

Laravel-Mix helper for projects with complex & multi assets. ?? Getting started Since mix introduced in laravel 5.4 it is recommended to use this pack

Fandogh 27 Oct 4, 2022
A Laravel response helper methods.

A Laravel response helper methods. The package respond provides a fluent syntax to form array or json responses.

Najm Njeim 5 Nov 2, 2021
Laravel FullCalendar.io Helper

Laravel 5 Full Calendar Helper For Laravel 4.2: use the laravel-4 branch This is a simple helper package to make generating http://fullcalendar.io in

Shawn Tunney 616 Dec 30, 2022
`dd` is a helper method in Laravel. This package will add the `dd` to your application.

dd dd is a helper method in Laravel. This package will add the dd to your application. Install Run composer require larapack/dd 1.* For Laravel Larave

Larapack 109 Dec 26, 2022
An opinionated support package for Laravel, that provides flexible and reusable helper methods and traits for commonly used functionality.

Support An opinionated support package for Laravel, that provides flexible and reusable helper methods and traits for commonly used functionality. Ins

Ian Olson 3 Apr 14, 2021
Active State Helper for Laravel Blade

laravel-activehelper Active State Helper for Laravel Blade Lightweight and simple Introduction Basically we do like this. <li class="sidebar {{ Reques

Ahmad Irsyadul Ibad 4 Sep 25, 2022