对刀片中的变量进行数学运算,转移到控制器

时间:2018-04-12 16:30:30

标签: php laravel

为了澄清,此行在网页上正确显示并显示正确的百分比,因此这非常有效。对于div本身而言,我直接在刀片上直接进行数学运算并不是很疯狂。

<div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center">{{ROUND((($snapshots[1]['COUNT'] - $snapshots[0]['COUNT']) / $snapshots[0]['COUNT'])*100,0)}}%</span></div>

I tried modifying it in the controller like so:

//this is the pre-existing variable where my data comes from
$snapshots = $callActivity->snapshot($this->slsno);

//this line was added for the percentage change
$percentChange = ($this->snapshots['CURRENT'] - $this->snapshots['PRIOR']) / $this->snapshots['PRIOR'];

//$snapshots was pre-existing, but I'm adding percentChange to the blade here
->with('snapshots', $snapshots)
->with('percentChange', $percentChange);

当我在这里转换$ percentChange时,我得到一个NAN值,但是如果我只是在上面执行硬编码的html,那么它的效果非常好。我只想尝试在控制器中执行此操作以保持刀片清洁。这里最好的方法是什么?

0 个答案:

没有答案