@foreach($journal->user as ...">

How to remove a comma from the last array in Laravel 5?

I have this view:

<p style="text-align: center;"><strong>
@foreach($journal->user as $item)
        {{ $item->name }},
@endforeach
</strong></p>

I wanted to remove the comma after the last line {{$ item-> name}}. How to do this in a Laravel 5.3 blade?

+4
source share
2 answers

If you are using 5.3, you can use $ loop for this:

@foreach($journal->user as $item)
    {{ $loop->first ? '' : ', ' }}
    {{ $item->name }}
@endforeach

Code from a similar question .

+6
source

try it

   @foreach($journal->user as $item)
        {{ $item->name }}
        @if (!$loop->last)
        ,
        @endif
   @endforeach
+2
source

Source: https://habr.com/ru/post/1661271/


All Articles