Laravel Framework | PHP & MySQL | Tutorials

David Carr

Laravel blade - Remove the last comma from array

Using the $loop variable ( The new $loop variable in Laravel 5.3 ) inside of a loop it’s easy to check when you're at the start or the end of a loop. In this case show a comma for all items except the last one we can use:

! $loop->last 

Which says then the loop is not the last item, at which points add the comma and close it with an endif.

@foreach($items as $item)
    {{ $item }}@if (!$loop->last),@endif



Domains are often purchased from multiple providers, keeping track of where a domain is and its DNS settings can be tricky. Domain Mapper solves this by listing all your domains in one place. View your DNS settings and receive reminders to renew your domains. Try it today.

Support my work by donating with PayPal.

Subscribe to my newsletter

Subscribe and get my books and product announcements.

© 2009 - 2021 DC Blog. All code MIT license. All rights reserved.