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’);

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...