Laravel Blade Remove the Last Comma from Foreach Loop

Utilizing the $loop variable within a loop makes it straightforward to determine whether you are at the beginning or the end of the loop.

We can determine the last loop like:


Now, let's try to remove comma from the last loop:

@foreach($posts as $post)

    {{ $post->title }} @if(!$loop->last),@endif