1. Go to this page and download the library: Download radiatecode/dastats 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/ */
radiatecode / dastats example snippets
use RadiateCode\DaStats\Facades\Stats;
.......
public function storeUser(Request $request){
// stores statements
............
Stats::title('User count')->key('total-user')->increase();
}
public function deleteUser($id){
// delete statements
............
Stats::key('total-user')->decrease();
}
use RadiateCode\DaStats\Facades\Stats;
.......
public function orderStore(Request $request){
// pending order placement statements
............
Stats::title('Pending order count')->key('total-pending-order')->increase();
}
public function orderDeliver(Request $request){
// order delivery statements
............
Stats::key('total-pending-order')->decrease();
}
use RadiateCode\DaStats\Facades\Stats;
.......
public function purchaseStore(Request $request){
// other statements
............
foreach($purchaseProducts as $product){ // multiple products
// purchase products save statements
..............
// increase stock for a product
Stats::title('Live stock')->key($product->id)->increase($product->quantity);
}
}
use RadiateCode\DaStats\Facades\Stats;
.......
public function purchaseUpdate(Request $request){
// other statement
............
foreach($purchaseProducts as $product){
// purchase products update statements
..............
..............
//live stock
$variation = (int) $newQty - $oldQty;
Stats::when($variation > 0,function ($stats) use ($product,$variation){
$stats->title('Live stock')->key($product->id)->increase($variation);
});
Stats::when($variation < 0,function ($stats) use ($product,$variation){
$stats->title('Live stock')->key($product->id)->decrease(abs($variation));
});
}
}
use RadiateCode\DaStats\Facades\Stats;
.......
public function productDelete($id){
// other statement
............
// find product
$purchaseProduct = PurchaseProduct::findOrFail($id);
// decrese value for this product
Stats::title('Live stock')->key($purchaseProduct->id)->decrease($purchaseProduct->quantity);
$purchaseProduct->delete(); // purchase product delete
}
// based on existence do stats operation
Stats::title('Title')->key('key-1')->exists(
function ($stats){ // if exists
$stats->replace(300);
},function ($stats){ // if not exists
$stats->increase(25);
}
);
Stats::contain('partOfkey')->get();
example:
// key name is `total-registered-user`
// we can get stats by the key part `registered`
Stats::contain('registered')->get();
use RadiateCode\DaStats\Jobs\SingleStatsJob;
use RadiateCode\DaStats\Enum\StatsAction;
..........
// dispatch the job to increase a stats
dispatch(new SingleStatsJob(StatsAction::INCREASE,'Title','key',$value));
or
// dispatch the job to decrease a stats
dispatch(new SingleStatsJob(StatsAction::DECREASE,'Title','key',$value));
// dispatch the job to replace a stats
dispatch(new SingleStatsJob(StatsAction::REPLACE,'Title','key',$value));
use RadiateCode\DaStats\Jobs\MultiStatsJob;
use RadiateCode\DaStats\Enum\StatsAction;
..........
$data = [
['key' => 1,'value' = 500],
['key' => 5,'value' = 152],
];
// dispatch the job to decrease multiple stats value
dispatch(new MultiStatsJob(StatsAction::DECREASE,'Title',$data));
// dispatch the job to increase multiple stats value
dispatch(new MultiStatsJob(StatsAction::INCREASE,'Title',$data));
use RadiateCode\DaStats\Jobs\MultiStatsJob;
use RadiateCode\DaStats\Enum\StatsAction;
..........
$data = [
['key' => 1,'value' = 500],
['key' => 5,'value' = 152],
];
$job = new MultiStatsJob(StatsAction::DECREASE,'Title',$data);
$job->withIsolation('Tenant',1001);
dispatch($job);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.