Answer the question
In order to leave comments, you need to log in
How to eagerly get the title of a related article?
Hello. Faced such problem: it is necessary, using eager loading in Laravel, to receive the list of comments and headings of the materials connected with them. The comment is related to several material types by the morphTo relationship. I do it like this:
$comments = Comment::with(['material' => function($query) {
$query->selectRaw('title');
}])->orderBy('id', 'desc')->take(15)->get();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question