引导轮播仅显示数据库中的三个图像

时间:2020-07-31 09:34:17

标签: laravel

我正在显示从数据库到轮播滑块的四个图像,但是只需要三个图像。滑块无法拍摄第一张图像。我很迷惑。为什么会这样?我的编码有问题吗?

控制器:

public function sliders()
    {
        $category = category::all();
        $data = DB::table('slider')
               ->select('slider.*')
               ->orderBy('slider_id', 'desc')
               ->get();
        return view('home',['data'=>$data])->with('category',$category);
    }

刀片:

<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
  <ol class="carousel-indicators">
    @foreach($data as $value)
                <li data-target="#carouselExampleIndicator" data-slide-to="{{ $loop->index }}" class="{{ $loop->first ? 'active' : '' }}"></li>
    @endforeach
  </ol>
  <div class="carousel-inner">
     @foreach($data as $key => $slider)
    <div class="carousel-item {{$key == 0 ? 'active' : '' }}">
        <img src="{{url('/images/slider', $slider->slider_images)}}" class="img-fluid"  alt="...">
    </div>
    @endforeach
  </div>
  <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

0 个答案:

没有答案