This is one of those situations where it's better to target the Post
model directly instead of the Postcategories
model. You could probably do this with a join instead of using relationships.
$posts = Post::select('posts.*')->join('postcategories', 'postcategories.id', '=', 'post.categories')->where('postcategories.slug', $category)->paginate();
I'm not sure if I got your table names right. But hopefully you get the idea.
As far as I understood you want to bring all posts from a certain category, right?
So try this:
$posts = Post::whereHas('catposts', function($query) use($category)
{
$query->where('slug', '=', $category);
})->paginate(1);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community