vendredi 27 septembre 2019

laravel: show both a particular post based on id and featured posts in one page

I have one post information page. posts/show.blade.php.

In this page,

I have one post information field and featured posts field.

In my controller, I have already put following code to show one particular post based on ID.

ResultsController.php

public function show($id,Post $post)
    {
        $post= Post::find($id);
        $post->category;
        $post ->tags;
        return view('posts.show',compact('post'));
    }

But also, I need to show featured events cards bottom of the same page(show.blade.php). I am thinking to add this code in my controller.

$posts = Post::latest()->limit(6)->get();
$categories = Category::latest()->limit(6)->get();

Because I want to show 6 featured posts.

So the question is how to show one particular post and the featured posts in one page.

I am glad if someone helps me out.

web.php

Route::get('results/{id}', 'ResultsController@show')->name('posts.show');

show.blade.php

//one of the cards for featured posts

 <div class="image">
                    <img src="../image/image2.jpg" alt="" width="300px" height="200px">
                </div>
                <div class="card-information">
                        <div class="event-name">
                            lorem
                        </div>
                        <div class="heart">
                            <i class="fas fa-heart fa-lg" style="color: #F70661"></i>
                        </div>

                    <div class="event-date">
                        2019.8.23
                    </div>
                    <div class="card-info">
                        <p>Lorem ipsum dolor sit amet in Lorem, ipsum dolor
                            <a href="#" style="color: white">...see more</a>
                        </p>
                    </div>
                </div>    


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2nI4noR
via IFTTT

Aucun commentaire:

Enregistrer un commentaire