L
L
Lucius Mooning2018-03-07 11:06:50
Laravel
Lucius Mooning, 2018-03-07 11:06:50

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

2 answer(s)
V
volodec, 2018-03-07
@volodec

A::orderby(sortPosition)->with('B')?

R
Roman Sokharev, 2018-03-09
@greabock

$posts = Post::with('comments')->get();
$allCommentsFromAllPosts = $collection->pluck('comments')->flatten();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question