Why I'm getting htmlenties() error

Published 2 years ago by Khudadad

I'm trying to display sum of a column but getting this error:

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

This is my code in the controller:

    $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();

And the View:

    {{ number_format($purchase->usd_total,2) }}

any help.

veve286

dd($purchase->usd_total) and you will see that it is object and not attribute.

Khudadad

When dd($purchase->usd_total) the result is :

"417.3280"
veve286

can u show me your entire blade file ?

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

Please sign in or create an account to participate in this conversation.