samedi 16 septembre 2017

How to display 'posts of the Day' in laravel

I am new to Laravel. I am creating a blog. In the homepage I have a carousel where I want to put 3 posts randomly for Everyday. For now I am using random(3); query as you can see in controller which gives three records randomly.

The problem is I want the posts for the whole day and in this method the posts change everytime the page refreshes. Please give me suggestion how to create "Posts of the day" in laravel 5.5 ? My codes are below. Thanks in advance...

HomeController file:

homepage.blade.php file:

<pre><code>
    public function homepage()
        {
            $randomPost = Post::all()->random(3);

            return view('user/pages/homepage',compact('randomPost'));
        }
</code></pre>
<pre><code>
    <div id="main-slider" class="flexslider">
        <ul class="slides">
            @foreach ($randomPost as $post)
                <li><a href="">
                    <img class="img-responsive img-thumbnail" src="" alt="" />
                    <div class="flex-caption">
                        <h3 style="color: #FFF; font-size:35px;"><b></b></h3>
                    </div></a>
                </li>
            @endforeach
        </ul>
    </div>
</code></pre>



Aucun commentaire:

Enregistrer un commentaire