Laravel-帖子轮播滑块不起作用

时间:2018-11-17 22:46:16

标签: php database laravel-5 carousel

我试图在轮播中滑动3个最新的博客帖子,但是当我将数据传递到视图中时,它列出了所有帖子,一个在另一个之上。

这是我的观点;

<section class="top-post-area pt-10">
    <div class="container no-padding">
        <div class="row small-gutters">
            <div class="col-lg-8 top-post-left">
                <div id="carouselExampleIndicators" class="carousel slide feature-image-thumb relative" data-ride="carousel">
                    <ol class="carousel-indicators">
                        <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
                        <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
                        <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
                    </ol>
                    <div class="carousel-inner">
                        @foreach ($slides as $post)
                            <div class="carousel-item active">
                                <div class="feature-image-thumb relative">
                                    <div class="overlay overlay-bg"></div>
                                    <img class="d-block w-100" src="/storage/{{$post->image}}" alt="First slide">
                                </div>
                                <div class="top-post-details">
                                    <ul class="tags">
                                        <li><a href="#">{{ $post->category->name }}</a></li>
                                    </ul>
                                    <a href="{{ url('article/'.$post->slug) }}">
                                        <h3>{{ $post->title }}</h3>
                                    </a>
                                    <ul class="meta">
                                        <li><a href="#"><span class="lnr lnr-user"></span>Igihozo Lise</a></li>
                                        <li><a href="#"><span class="lnr lnr-calendar-full"></span>{{date('j M, Y',strtotime($post->created_at))}}</a></li>
                                        <li><a href="#"><span class="lnr lnr-bubble"></span>{{ $post->comments()->count() }} Comments</a></li>
                                    </ul>
                                </div>                            
                            </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>
            </div>
        </div>
    </div>
</section>

这是我的功能:

 $slides = Post::orderBy('created_at', 'desc')->limit(3)->get();
        return view('pages.home')->with(['slides' => $posts, 'categories' => $categories]);

当我删除活动班级时,没有帖子显示。

我的问题是

  1. 为什么限制条件不起作用(我收到3篇以上的文章)
  2. 如何在轮播中正确滑动这些帖子?谢谢

0 个答案:

没有答案