1. Go to this page and download the library: Download white-frame/statistics library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
white-frame / statistics example snippets
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);
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())
// 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;
}
});
$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 ...
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.