lundi 28 mai 2018

How to display recently created pages on page using Laravel?

Lot of articles showing how to display on homepage, but what about on another page such as a page?

This is what I have in my controller file:

public function page($slug)
{
    $page = MenuPage::where('slug',$slug)->firstOrFail();
    return view('pages.page', compact('page'));

}

page.blade.php has my page layout code.

Curious to know what code to put into the controller file and what to put in the view file?

I saw this code in one article for the controller file to display recent posts:

 $recentPosts = Post::take(5)->latest()->get();

but where would I put that code at?

In the backend where I manage the list of pages, this is the code used to show the list of pages:

                        @foreach($pages as $page)

                          <tr>

                            <td></td>
                            <td></td>
                            <td></td>
                          </tr>
                       @endforeach

If I put that code into my page layout, I get an "Undefined variable: pages" error.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire