syrian-open-source/laravel-relational-metrics

此包将帮助您获取模型指标以及相关模型的指标,这有助于您避免编写过多的请求或查询。

v1.2.0 2022-03-21 21:14 UTC

This package is auto-updated.

Last update: 2024-09-22 03:02:31 UTC


README

logo

PHP Composer Run tests

关系型指标

此包将帮助您使指标更容易,您可以获取有关模型的指标,基于它们关系的模型,甚至可以根据多个条件获取有关模型的指标!

要获取拥有价格超过x美元的产品数量的商店,将非常简单;)

1 - 依赖

第一步是使用composer安装包并自动更新您的composer.json文件,您可以通过运行以下命令完成此操作:

composer require syrian-open-source/laravel-relational-metrics

用法

        // 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,
	  *	];
	  *	
        */

接下来您可以做什么,您可以获取基于模型关系的模型指标!

假设我们想要获取拥有价格超过500美元的产品的商店数量

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

在先前的示例中,该包将返回拥有价格等于500美元的产品的商店数量

最后但同样重要的是,您可以获取基于任何数量条件的模型指标!

        // 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,
	  *	];
	  *	
        */

在先前的示例中,该包将返回地址包含"UAE"且评分超过3的商店数量

更新日志

有关最近更改或更新的更多信息,请参阅更新日志

安全

如果您发现任何与安全相关的问题,请首先通过zainaldeenfayod@gmail.com发送电子邮件,如果我们在短时间内没有修复它,请创建一个新问题,描述您的问题。

致谢

包标志由

关于叙利亚开源

叙利亚开源平台是GitHub上第一个致力于将来自不同文化和经验的叙利亚开发者聚集在一起的平台,共同在不同语言、任务和版本的项目上工作,并努力吸引叙利亚开发者在一个平台上为开源软件做出更多贡献,对其进行开发,并以高质量和先进的工程功能发布它。这激发了开源概念在叙利亚软件社区中的传播,同时也通过分布式系统和团队的工作提高了开发者的效率。