Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Snapey's avatar

you can use null coalesce operator ??

no need for @isset

<td>{{ $latestprices->where('product_id',$product->id)->first()->rate_per_kg ?? 0 }}
  </td>
siangboon's avatar

really, I felt like you treat snapey as your behind scene coder.... being a developer is so easy with snapey... hahaha....

AbdulBazith's avatar

@siangboon not like that, but when we struct in coding, suddenly it remembers Laracast, when it comes to laracast it remembers @snapey .. thats the reason..

AbdulBazith's avatar

@snapey sorry for disturbing you once again,

small doubt

if i need the overall total amount of the <td>{{ $latestprices->where('product_id',$product->id)->first()->rate_per_kg * $product->openingstock->open_qty }} </td>

the above query is in forloop, so for each product the rate is multiplied with qty and displayed. i need the overall amount at last after the foreach means what should i do?

this means what should i do??

Snapey's avatar

You could just add it in the view?

<td>{{ $latestprices->where('product_id',$product->id)->first()->rate_per_kg * $product->openingstock->open_qty }} </td>

@php $total +=  $latestprices->where('product_id',$product->id)->first()->rate_per_kg * $product->openingstock->open_qty @endphp

Previous

Please or to participate in this conversation.