【问题标题】:How to handle htmlentities() exception in Laravel如何在 Laravel 中处理 htmlentities() 异常
【发布时间】:2023-03-19 12:55:01
【问题描述】:

每个人。我面临以下错误

htmlentities() expects parameter 1 to be string, object given (View: E:\accounting\resources\views\index.blade.php)

在 laravel 中运行此查询并且不知道我缺少什么时,请提供任何帮助。 谢谢 查询:

 $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 laravel-query-builder


    【解决方案1】:

    您可以在打印$purchase->usd_total

    之前检查$purchase变量是否有数据

    在您的查看页面中,您可以检查以下内容

    @if(count($purchase)>0)
    
    {{ number_format($purchase->usd_total,2) }}
    
    @endif
    

    当然你也可以用php if。我用过blade if

    希望这会有所帮助。 :) :) :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-15
      • 2016-11-22
      • 2018-11-30
      • 1970-01-01
      • 2014-04-22
      • 2013-10-22
      • 1970-01-01
      相关资源
      最近更新 更多