简体   繁体   English

如何在 Laravel 刀片视图中进行算术运算?

[英]How to do arithmetic operations in Laravel blade view?

I want to do subtraction operations inside the Laravel blade view.我想在 Laravel 刀片视图中进行减法运算。 I knew it was the wrong approach I need to do it from the controller, but can someone give me the proper solution to do it directly inside the blade view?我知道这是我需要从控制器执行此操作的错误方法,但是有人可以给我正确的解决方案以直接在刀片视图中执行此操作吗?

Note: I am a newbie to programming.注意:我是编程的新手。

Here is my code这是我的代码

@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}}

Optimal way for doing this will be to this in the DB query itself.执行此操作的最佳方法是在数据库查询本身中执行此操作。

Here is the raw query sample这是原始查询示例

SELECT all_due, total_due, (all_due-total_due) as old_due FROM reciept_details;

Database engines are usually optimized to do these kinds of operations, and this will also save some resources on your application server.数据库引擎通常经过优化以执行这些类型的操作,这也将节省应用服务器上的一些资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM