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:
$loop->last
Now, let's try to remove comma from the last loop:
@foreach($posts as $post)
{{ $post->title }} @if(!$loop->last),@endif
@endforeach
Md Obydullah
Software Engineer | Ethical Hacker & Cybersecurity...
Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.