Answer the question
In order to leave comments, you need to log in
How to get a collection of related elements to a sorted collection of parent objects?
Good afternoon!
How to get a collection of related elements to a sorted collection of parent objects?
For example,
A ->hasMany(B)
Collection of parent elements: A->orderby(sortPosition).
I would like to get: a collection B of elements, as when passing elements in a sorted collection A.
.
Answer the question
In order to leave comments, you need to log in
$posts = Post::with('comments')->get();
$allCommentsFromAllPosts = $collection->pluck('comments')->flatten();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question