PHP code example of syrian-open-source / laravel-relational-metrics

1. Go to this page and download the library: Download syrian-open-source/laravel-relational-metrics 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/ */

    

syrian-open-source / laravel-relational-metrics example snippets


        // first you must make a model from facade class
        // like post model 
        $instance = \SOS\RelationalMetrics\Facades\RelationalMetricsFacade::setModel("Post"); 
        // or you can specify thr model name by this way:  RelationalMetricsFacade::setModel(Store::class); 

        $metrics = $instance->getBasicMetrics();
        // or you can get the count or the message directly.
        $directCount = $instance->getCount(); 
        $directName = $instance->getName(); 

        /*
	  *     Response will be like:
	  *	[
	  *	    'name' => 'Total Stores Number,
	  *	    'count' => 43,
	  *	];
	  *	
        */

        $metrics = $instance->getRelationalMetrics($relationName, $relationColumn, $value);
        // example: $instance->getRelationalMetrics('products, 'price', 500);
        /*
	  *     Response will be like:
	  *	[
	  *	    'name' => 'Total Stores Number,
	  *	    'count' => 12,
	  *	];
	  *	
        */

        // example for the conditions
        $conditions = [
                  ['method' => 'where', 'column' => 'address', 'operator' => 'like', 'value' => '%UAE%'],
                  ['method' => 'where', 'column' => 'rate', 'operator' => '>', 'value' => 3],
        ];
        $metrics = $instance->getRelationalMetrics($conditions);
        	
        /*
	  *     Response will be like:
	  *	[
	  *	    'name' => 'Total Stores Number,
	  *	    'count' => 2,
	  *	];
	  *	
        */