我想创建一个发票的税务摘要,其中我想根据不同的税率添加总计。例如:- 2.5% 税率有自己的产品,6% 税率有自己的产品。我想这样做在 for 循环中。我使用了以下代码,但它不起作用。请告诉我这段代码有什么问题。它没有显示正确的总计。我有一个表名称是 sales_items。字段有id,invoice_id,cgst_percentage,cgst_amount,sgst_percentage等。如图
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
最佳答案
$value
变量是一个对象,用于保存 cgst_unique_data
查询结果中的一行。您不能像在
$data_total= $data_total + $value;
您需要访问要添加的行中的特定列。如果列名称是 someName
,您需要执行以下操作:
$data_total= $data_total + $value->someName;
关于php - (2/2) ErrorException stdClass 类的对象无法在 laravel 5 中转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46986184/