【发布时间】:2017-03-20 13:39:07
【问题描述】:
我正在尝试计算电子商务应用中产品的含税价格。在表格税中,我有以下列:
id - iso_code - vat.
我的查询以获取特定国家/地区的增值税信息:
$taxRate = DB::table('tax')
->select('vat')
->where('iso_code', $productcountryid)
->get();
如果我 print_r 我获得的 $taxRate 值
Illuminate\Support\Collection Object ( [items:protected]
=> Array ( [0] => stdClass Object ( [vat] => 1 ) ) )
检索我使用的增值税值:
$taxRates=$taxRate[0]['tax'];
我得到以下信息:
不能使用 stdClass 类型的对象作为数组
另一方面,使用
$taxRates = $taxRate->vat;
错误:未定义属性:Illuminate\Support\Collection::$vat
我的想法是使用 $taxRate 值来获得一个简单的计算
priceamount = $productprice * $taxRate
使用@assada 建议更新 ------
$array = $taxRate->toArray();
(array)[0]['vat']
给出错误:
不能使用 stdClass 类型的对象作为数组
任何有关如何处理集合中返回的值的帮助表示赞赏。 brgds。
【问题讨论】:
标签: php mysql laravel-5 eloquent