samedi 17 novembre 2018

Laravel - Posts Carousel Slider not working

I am trying to slide the 3 latest blog posts in a carousel but when I pass the data into the view, it lists all the posts, one on top of the other;

Here is my view;

<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/" alt="First slide">
                                </div>
                                <div class="top-post-details">
                                    <ul class="tags">
                                        <li><a href="#"></a></li>
                                    </ul>
                                    <a href="">
                                        <h3></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></a></li>
                                        <li><a href="#"><span class="lnr lnr-bubble"></span> 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>

And this is my function:

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

When I delete the active class, no post is showing up.

My questions here are;

  1. Why the limit condition is not working( I'm getting more than 3 articles)
  2. How can I slide these posts properly in the carousel? Thank you


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire