[英]How to do arithmetic operations in Laravel blade view?
我想在 Laravel 刀片视图中进行减法运算。 我知道这是我需要从控制器执行此操作的错误方法,但是有人可以给我正确的解决方案以直接在刀片视图中执行此操作吗?
注意:我是编程的新手。
这是我的代码
@if(!empty($receipt_details->total_due))
<tr>
<th>
Customer Old Due
</th>
<td>
{{$receipt_details->all_due}} - {{$receipt_details->total_due}}
</td>
</tr>
@endif
您可以像这样在同一个{{}}
添加它
{{$receipt_details->all_due - $receipt_details->total_due}}
执行此操作的最佳方法是在数据库查询本身中执行此操作。
这是原始查询示例
SELECT all_due, total_due, (all_due-total_due) as old_due FROM reciept_details;
数据库引擎通常经过优化以执行这些类型的操作,这也将节省应用服务器上的一些资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.