I had a similar issue. I only wanted to show active posts on blog page. I fixed it after seeing your post. In controller I am using if statement to pass value of $post. If we don't give a default value the error I got was post variable not defined. Work in progress so I will be refactoring it later.
In controller
public function index(){
$posts=Post::where('status','=',1)->orderBy('published_at', 'DESC')->paginate(8);
if(!empty($post)){
return view('frontend.blog',compact('posts'));
}
else{
$post='0';
return view('frontend.blog',compact('posts'));
}
}
In view
<div class="card-deck">
@if($post=!0)
@foreach($posts as $post)
<div class="card" style="min-width:300px; margin-top:30px; margin-bottom: 30px;">
<a href="{{route('blog.page',[$post->slug])}}"><img src="{{asset('storage/'.$post->image)}}"
class="card-img-top" alt="..."></a>
<div class="card-body">
<div style="margin-bottom:10px;">
<button type="button" class="btn btn-primary btn-sm" disabled>Category</button>
</div>
<h3 class="card-title">{{$post->post_title}}</h3>
<div>
<small class="text-muted">By:{{$post->author}}</small>|
<small class="text-muted">{{date('d-M-Y', strtotime($post->published_at))}}</small>
</div>
<div style="margin-top:10px;">
{!!html_entity_decode(str_limit($post->content,40) )!!}
<a href="{{route('blog.page',[$post->slug])}}">Read more ></a>
</div>
</div>
<div class="card-footer">
<small class="text-muted">Comments </small><i class="fas fa-comments fa-sm"></i> |
<small class="text-muted">Likes </small><i class="far fa-heart fa-sm"></i>|
<small class="text-muted">Views </small><i class="far fa-eye fa-sm"></i>
</div>
</div>
@endforeach
@endif
</div>
@if(!empty($post))
{{ $posts->links()}}
@endif
Critique of this code by seniors is welcome since I am a beginner and I may be using coding techniques which cause bugs later. PS: The code formatting seems to have gone wrong and I don't know how to fix it inside the comment form