W
W
WhatYouDoing2019-11-22 09:22:19
Laravel
WhatYouDoing, 2019-11-22 09:22:19

How to make connection in laravel?

And so the essence of the question, the comment has answers, so how can I get the author from these answers, if it’s easy for just comments, but with replies I can’t even get the author, I pull it out with such a request

Comment::orderBy('created_at', 'asc')->parent()->with('replies','user')->get()
in the model
public function user(){
        return $this->belongsTo(User::class, 'user_id');
    }

{
id: 25,
parent_id: null,
message: "Test",
user_id: 1,
created_at: "2019-11-21 22:15:36",
updated_at: "2019-11-21 22:15:36",
replies: [
{
id: 26,
parent_id: 25,
message: "reply test",
user_id: 1,
created_at: "2019-11-21 22:15:48",
updated_at: "2019-11-21 22:15:48"
}
],
user: {
id: 1,
name: "Олег Николаевич Воробьев",
email: "[email protected]",
created_at: "2019-11-21 21:19:31",
updated_at: "2019-11-21 21:19:31"
}
},

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin B., 2019-11-22
@WhatYouDoing

Comment::orderBy('created_at', 'asc')->parent()->with(['replies.user', 'user'])->get()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question