如何获得laravel中列值的平均值

2021-12-18 00:00:00 php laravel laravel-5 laravel-5.3

假设我有这个专栏

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

它有七行并且有整数值!我想让它添加并除以存在的行.

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

相关文章