如何从公用文件夹中逐个显示所有图像

时间:2017-12-26 16:54:47

标签: twitter-bootstrap laravel

当我运行此代码时,它会显示我公共文件夹中的所有图像,但我想逐个显示它们。

 <div id="mycarousel" class="carousel slide" data-ride="carousel">
      <div class="carousel-inner" role="listbox">
      <div class="item active">
         @foreach ($images as $image)
          <img src="{{ asset('images/' . $image->getFilename()) }}">
        @endforeach
</div>
</div>
   <a class="left carousel-control" href="#mycarousel" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
   <span class="sr-only">Previous</span>
   </a>
   <a class="right carousel-control" href="#mycarousel" role="button" data-slide="next">
   <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
   <span class="sr-only">Next</span>
   </a>
</div>

控制器

$images = \File::allFiles(public_path('images'));

return view('welcome')->with('images',$images);

2 个答案:

答案 0 :(得分:1)

    @foreach ($images as $image)
     <div class="item">
      <img src="{{ asset('images/' . $image->getFilename()) }}">
     </div>
    @endforeach

答案 1 :(得分:0)

你必须把class =&#34; item&#34;在foreach中,保持class =&#34; item active&#34;。

此外,您还错过了旋转木马指示符,以便箭头可以显示下一张和上一张图像。

https://www.w3schools.com/bootstrap/bootstrap_carousel.asp