I'm facing an issue on understanding the content of the index function in the controller
I'm trying to get all the posts from my posts table into a view
my index function
public function index()
{
$posts=\App\post::all();
return view('MainViews.welcome',compact('posts'));
}
my view
<div class="row">
@foreach($posts as $post)
<div class='col-md-8'>
<div class="post"></div>
h3></h3>
<a href="#" class="btn btn-primary">read it</a>
<p>
</p>
</div>
@endforeach
</div>
I'm getting Undefined variable error and highlighting @foreach
and I have a question when to use compact and when I can user an array
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire