Halit Ozdogru
Halit Ozdogru

Reputation: 3

Laravel blade button foreach

I want to show one or more JPG files with a button, I use a foreach loop to show these images but currently I get 2 buttons when I have 2 files. How can I get only one button even if I have multiple images.

@foreach($letter->documents AS $document)
  @for($page = 1; $page <= $document->pages; $page++)
    <input onclick="window.open('{{ '/send/'.$letter->id.'/documents/'.$document->id.'/'.$page.'/778x1008'}}')" value="View PDF example" type="button" class="left"></input>
  @endfor
@endforeach

Upvotes: 1

Views: 842

Answers (1)

milo526
milo526

Reputation: 5083

Laravel loops have an inherit $loop variable of which documentation can be found here.

In short one could use:

@foreach($letter->documents AS $document)
  //Show image
  @if ($loop->last)
    //Create button
  @endif
@endforeach

Upvotes: 1

Related Questions