Jump to content

Recommended Posts

Posted

I am building blog commenting system, using laravel 5.8 and vue.js. I want to add paginate function to comments as per instructions https://adevait.com/laravel/laravel-overwriting-default-pagination-system.

Now I can display five comments, and after I click load more,

I want to show next five comments.

I have no idea how to accomplish. I am glad if someone helps me out.

comments.vue

user
Cancel Comment

{{ comment.user.name }}
{{ comment.body }}

commentsController.php

public function index(Post $post)
{
return $post->comments()->with(‘user’)->paginate(5);
}
ResultsController.php

 

public function show(Post $post)
{
$recommended_posts = Post::latest()
->whereDate(‘date’,’>’,date(‘Y-m-d’))
->where(‘category_id’,’=’,$post->category_id)
->where(‘id’,’!=’,$post->id)
->limit(7)
->get();

// load the post comments here
$post->load('comments');
$posts['particular_post'] = $post;
$posts['recommended_posts'] = $recommended_posts;

return view('posts.show',compact('posts'));
}
show.blade.php

 

Route::get(‘results/{post}’, ‘ResultsController@show’)->name(‘posts.show’);
Route::get(‘results/{post}/comments’, ‘CommentsController@index’);

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...