I have an error
does not exist on this collection instance.
In my show .blade.php, I want to show ten featured posts.
So in my controller I used get() method. And in my view page, I used @foreach. But it doesn't work.
Instead of get(), I used first(). Then It worked. I could show only the latest post.
But it is not what I want to accomplish. Because
I want to show the ten latest posts.
ResultsController.php
public function show($id,Post $post)
{
$particular_post= Post::find($id);
$featured_posts = Post::latest()->limit(10)->get();
$posts['particular_post'] = $particular_post;
$posts['featured_posts'] = $featured_posts;
return view('posts.show',compact('posts'));
}
show.blade.php
@foreach($posts['featured_posts'] as $featured_post)
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="image">
<img src="" alt="" width="300px" height="200px">
</div>
<div class="card-information">
<div class="event-name">
</div>
<div class="heart">
<i class="fas fa-heart fa-lg" style="color: #F70661"></i>
</div>
<div class="event-date">
</div>
<div class="card-info">
<p>
<a href="#" style="color: white">...see more</a>
</p>
</div>
</div>
</div>
@endforeach
web.php
Route::get('results/{id}', 'ResultsController@show')->name('posts.show');
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire