سلام
توی درس های اشتراک گذاری ویدیو با لاراول بخش سطح بندی کامنت ها تا بینهایت level توضیح داده شده .
جناب موسوی اگر لطف کنید و نحوه صفحه بندی کردن (pagination) کامنت ها را هم بفرمائید.
متشکرم.
منظورم این درس هست
https://roocket.ir/series/video-sharing-project-with-laravel/episode/20
سلام متشکرم از پاسخ شما
این روش رو بلد بودم اگر اون درس رو ببینید کل مجموعه نظرات در قالب یک helper function قرار گرفته و خروجی اون هم یک string هست
function commentdiscussion( Discussion $discussion , $parentId ='0' )
{
$comments = $discussion->commentdiscussions()->where('parent_id', $parentId)->get();
if(count($comments) <= 0) {
return null;
}
$commentBody = '';
foreach ($comments as $comment)
{
$commentBody .='';
$commentBody .='<div class="row no-gutters border">';
$commentBody .='<div class="col-3 color rigchlightyellowtwo item text-center">';
$commentBody .='</div>';
$commentBody .='</div><br>';
$commentBody .='<div class="blog-comment margin-left-comment">' . commentdiscussion($discussion, $comment->id) . '</div>';
}
return $commentBody;
}
خروجی توی blade هم
{!! commentdiscussion($discussion) !!}
توی همچین حالتی میخوام که paginate داشته باشه
البته من برای کوتاه شدن جواب بخشی از function رو حذف کردم که فقط مساله رو عنوان کرده باشم
@sadeqi
در همین هلپر که شما دارید استفاده میکنید ، دارید از مدل Discussion استفاده میکنید و این مدل از Eloquent ORM ارثبری میکنه. و این باعث میشه بتونید بجای متد get از paginate استفاده کنید; به کد زیر دقت کنید:
function commentdiscussion( Discussion $discussion , $parentId ='0' )
{
$comments = $discussion->commentdiscussions()->where('parent_id', $parentId)->paginate(2);
if(count($comments) <= 0) {
return null;
}
$commentBody = '';
foreach ($comments as $comment)
{
$commentBody .='';
$commentBody .='<div class="row no-gutters border">';
$commentBody .='<div class="col-3 color rigchlightyellowtwo item text-center">';
$commentBody .='</div>';
$commentBody .='</div><br>';
$commentBody .='<div class="blog-comment margin-left-comment">' . commentdiscussion($discussion, $comment->id) . '</div>';
}
$commentBody .= '<div>'. $comments->links() .'</div>';
return $commentBody;
}