如何在laravel中获取列值的平均值

问题描述:

让我说我有此专栏

star
----
1    
3    
3    
1    
2    
5    
3

它有7行,并且有整数值!我想添加它并除以其中的行.

It has seven rows and there are integer values! I want to have it added and divided by the rows there are.

我如何在laravel中做到这一点.我可以用普通的php来做,但是我想在laravel中学习.

How do I do it in laravel. I can do it in plain php but I want to learn it in laravel.

尝试一下:

$avgStar = Model::avg('star');

型号"将替换为您的型号名称

" Model " will replace with your model name