2017-05-30 97 views
1

我想用一个按钮显示一个或多个JPG文件,我使用foreach循环来显示这些图像,但是当我有2个文件时,我现在得到2个按钮。即使我有多个图像,我如何只能获得一个按钮。Laravel blade button foreach

@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 
+0

欢迎SO。请阅读这个[how-to-ask](http://stackoverflow.com/help/how-to-ask)并遵循那里的指导原则,用附加信息来完善您的问题,例如代码和错误消息来描述您的编程问题。 – thewaywewere

回答

1

Laravel回路具有一个继承$loop可变其中文档可以发现here

总之一个可以使用:

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

非常感谢你milo526为你帮助它为我工作 –