(2/2)ErrorException类ladvel 5

时间:2017-10-28 04:15:28

标签: php mysql laravel laravel-5 eloquent

我想创建发票的税务摘要,其中我想根据不同的税率添加总额。例如: - 2.5%的税率有自己的产品,6%的税率有自己的产品。我想这样做在for循环中。我使用了以下代码,但它没有用。请告诉我这段代码有什么问题。它没有显示正确的总数。我的表名是sales_items。它的字段是id,invoice_id,cgst_percentage,cgst_amount,sgst_percentage等。图像为

enter image description here

Controller.php

    $data['query1']= DB::table('sales_items')->distinct()->get(['cgst_percentage']);
    // I am using this variable in foreach loop in view file.

View.blade.php

    <?php $data_total= array();  ?>
    <?php $cgst_unique_data= array(); ?>

 @foreach($query1 as $cgst_data=>$value)


    <?php 

    $cgst_unique_data= DB::table('sales_items')->where('cgst_percentage','=',$value->cgst_percentage)->where('invoice_id','=',$sales_item->invoice_id)->get();

    ?>

     @foreach($cgst_unique_data as $total=>$value) 

     <?php

     $data_total = $total_amount + $total;
     $data_total= $data_total + $value;
     ?> 
     @endforeach

     {{ $data_total }}

 @endforeach

1 个答案:

答案 0 :(得分:1)

$value变量是一个对象,它包含cgst_unique_data个查询结果中的一行。您不能像在

中那样将其添加到其他整数变量中
$data_total= $data_total + $value;

您需要访问要添加的该行的特定列。如果列名称为someName,则您需要执行以下操作:

$data_total= $data_total + $value->someName;