Answer the question
In order to leave comments, you need to log in
How to display Laravel ready comments?
when loading comments with ajax
$('#moreComments').on('click', function () {
$.post($(this).data('href'), function (data) {
console.log(data);
});
});
public function more(Request $request,$content,$type,$tale){
if ($request->ajax()){
$comArray = array();
$moreComments = 0;
$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(); //Всего комментариев
$getComments = 2; //По сколько подгружаем
if ($countComments <= 2){ //Если количество оставшихся комменариев меньше либо равно общему количеству
$moreComments = 0;
$getComments = 0;
}else{
$moreComments = $countComments - 2; //Присваем переменно количество оставшихя комментариев
if ($moreComments <= $getComments) $getComments = $moreComments; //Запись вида - показать $getChildrens из $moreChildrens
}
foreach ($comments as $comment) {
$moreChildrens = 0; //Всего дочерних комментариев
$getChildrens = 6; //По сколько подгружаем
$queryChildrens = Comment::where('parent','=', $comment->id);
$childrens = $queryChildrens->take(6)->get();
$count = $queryChildrens->count();
if ($count <= 6){ //Если количество оставшихся комменариев меньше либо равно общему количеству
$moreChildrens = 0;
$getChildrens = 0;
}else{
$moreChildrens = $count - 6; //Присваем переменно количество оставшихя комментариев
if ($moreChildrens <= $getChildrens) $getChildrens = $moreChildrens; //Запись вида - показать $getChildrens из $moreChildrens
}
$comment->childrens = $childrens;
$comment->more_childrens = $moreChildrens;
$comment->get_childrens = $getChildrens;
}
return new CommentCollection($comments, $moreComments);
}
}
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