I have nested replies like the following:
comment
-reply1
--reply3
---reply4
----reply5
-reply2
--reply6
I have this function in my model
return $this->hasMany(self::class, 'parentid', 'postid')
->visible()
->with('replies');
and I wrote this code to get all replies
foreach($replies as $reply){
if(!empty($reply->replies)){
foreach($reply->replies as $re){
$replies->push($re);
}
}
}
return $replies;
this code can get the following replies:{reply1,reply2,reply3,reply6} How can I retrieve all the replies even if there are deeper replies without using recursion???