【问题标题】:How to sole htmlentities() error in Laravel如何在 Laravel 中解决 htmlentities() 错误
【发布时间】:2016-06-13 16:01:23
【问题描述】:

我正在尝试使用查询生成器在 laravel 中显示某些列的总和,但出现此错误:

htmlentities() expects parameter 1 to be string, object given

这是查询:

$purchase = DB::table('purchases')
    ->join('currencies', 'currencies.cur_id', '=', 'purchases.currency_id')
    ->selectRaw('purchases.*, currencies.currency ,SUM(purchases.quantity*unit_price) as total, SUM(purchases.c_price*quantity) as usd_total')
    ->first();

并查看:

<div class="col-xs-8">
      <p class="text-elg text-strong mb-0">
          {{ number_format($purchase->usd_total,2) }}
       </p>
           <span>Purchases</span>
 </div>

【问题讨论】:

    标签: laravel-5.2


    【解决方案1】:

    dd($purchase->usd_total)你会找到原因的。

    【讨论】:

    • dd($purchase->usd_total) 的结果是“44,1290”
    • 你检查查询了吗?尝试回显查询是否正确
    • 当我 dd($purchase) 输出这个 {#111 ▼ +"id": 1 +"item_name": "Muscle" +"quantity": 12 +"unit_price": "100.0000" +"c_price": "1.4440" +"description": "" +"buy_date": "2016-06-12" +"purchase_type_id": 1 +"unit_id": 1 +"currency_id": 2 +"rate_id": 4 +“brand_id”:1 +“category_id”:1 +“created_at”:“2016-06-12 22:35:10”+“updated_at”:“2016-06-12 22:35:10”+“货币": "AFN" +"total": "28900.0000" +"usd_total": "417.3280" }
    猜你喜欢
    • 2022-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-01
    • 2015-10-14
    • 2016-01-29
    • 2021-09-15
    • 2018-01-22
    相关资源
    最近更新 更多