comments: {},
total,
...
public function more(Request $request,$content,$type,$tale){
if ($request->ajax()){
$query = Comment::where('content_id', $content)->where('type', '=', $type)->where('parent','=',0)->orderBy('id', 'desc')->skip($tale);
$comments = $query->take(2)->get();
$countComments = $query->get()->count(); //Total comments
foreach ($comments as $comment) {
$moreChildrens = 0; //All child reviews
$getChildrens = 6; //how many loadable
$queryChildrens = Comment::where('parent','=', $comment->id);
$childrens = $queryChildrens->take(6)->get();
$count = $queryChildrens->count();
if ($count <= 6){ //If the remaining number of comments is less than or equal to the total number
$moreChildrens = 0;
$getChildrens = 0;
}else{
$moreChildrens = $count - 6; //variable Presuem the number of remaining review
if ($moreChildrens <= $getChildrens) $getChildrens = $moreChildrens; //the asterisk is to show $getChildrens of $moreChildrens
}
$comment->childrens = $childrens;
$comment->more_childrens = $moreChildrens;
$comment->get_childrens = $getChildrens;
}
}
}
Find more questions by tags Laravel