Fixed an error in the question regarding the subquery. Should make more sense now.
->with(['children' => function ($query)
{
$query->take(3);
}])
will take 3, but for whole collection.
I would make a new relationship something like children3
return $this->hasMany('App\Message', 'parent_id', 'id')->take(3);
and then
$messages = Message::select('messages.*')
->where('post_id', 1)
->where('parent_id', 0)
->with('children3')
->paginate(10);
I tried your recommendation (children3
), but it's still only returning a total of 3 children (i.e. only for the first parent result).
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community