Phi*_*ind 3 php laravel laravel-5
我试图在我的Laravel网站上计算一些统计数据...但是当我执行以下代码时,它给了我一个'除以零错误'
我理解为什么因为没有记录所以计算是0除0
有没有办法,如果它eqauls零回显'0'而不是抛出该错误
Controlller
private function getAverageOddsForLastMonth()
{
$firstDayOfLastMonth = new Carbon('first day of last month');
$lastDayOfLastMonth = new Carbon('last day of last month');
$tipslastmonth = Tip::whereBetween('tip_date',
[
$firstDayOfLastMonth,
$lastDayOfLastMonth
]
)->count();
$sumOfTheOddsLastMonth = Tip::whereBetween('tip_date',
[
$firstDayOfLastMonth,
$lastDayOfLastMonth
]
)->sum('odds');
return ($sumOfTheOddsLastMonth / $tipslastmonth);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7566 次 |
| 最近记录: |