What is that you want to achieve exactly?
And are you aware that this:
$categories = Category::with(['posts'=> function($query)
{
$query->take(4);
}])->get()
is going to limit all related posts
(total 4 posts will be loaded, not 4 per category
)
yes, i am aware of it. what i want to do is.
get all categories and 4 posts in it.
when somewhere in the view, i get to filter to get the category with name = 'sports'
The filter you have there is correct. So what is the issue?
Can you not do $sport->posts()
?
Anyway, do a dd($sports)
. It will help you get a view of all properties of the $sports
object.
mcraz said:
Can you not do
$sport->posts()
?Anyway, do a
dd($sports)
. It will help you get a view of all properties of the$sports
object.
i can't, the scenario is this, i need to filter the posts because i will display 4 posts per category in the frontpage, and the order is manually arranged.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community