如何删除laravel中foreach循环的最后一项中的逗号?

I tried adding last item logic using if condition, but the code is getting displayed.

My existing code :

<script type='application/ld+json'> 
{
  "itemListElement":
[
  @foreach($product->Offers as $offer)
   {
    "@type": "Offer",
    "name": "{{$offer->title}}",
    "price": "{{$offer->displayPrice}}",
   },  
   @endforeach 
 ]
}

}
</script>

Try to do this

<?php $i = 1; $len = count($product->Offers); ?>
@foreach($product->Offers as $offer)
  {
  "@type": "Offer",
  "name": "{{$offer->title}}",
  "price": "{{$offer->displayPrice}}",
  }<?php if($i < $len){echo ',';} $i++;?>
@endforeach

Try to use $loop->last():

@foreach($product->Offers as $offer)
{
    "@type": "Offer",
    "name": "{{$offer->title}}",
    "price": "{{$offer->displayPrice}}",
}{{ $loop->last() ? '' : ',' }}
@endforeach