It might help to share some of your code
Sep 2, 2020
4
Level 4
How to use @foreach on index page
Good practice of using @foreach on the homepage.
I am trying to design two pages with different styles with posts loop from the database. One page is inside the member's area which is linked in the dashboard, so members can see it. Also, non-members can visit it if they have the link.
But I want to show the same list with a different style on the homepage. So how to use the @foreach and pass the value for the variable?
Basically, the question is about passing error. "Undefined variable:"
Level 75
You can use partial view for that for example
@include('partials.list-of-posts', ['posts' => $posts, 'class' => 'your-class'])
where you pass $posts variable and inside that view you have foreach
@foreach ($posts as $post)
//
@endforeach
So you just include it to your homepage and dashboard page.
Please or to participate in this conversation.