Support the ongoing development of Laravel.io →
Eloquent Views Blade
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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);
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

azielazny azielazny Joined 9 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.