S
S
Sukhrob Saidov2017-05-25 05:32:14
Laravel
Sukhrob Saidov, 2017-05-25 05:32:14

How to pass pagination to ajax?

How to send pagination to ajax request?
A simple ajax pass example:

$posts=Post::where('category_id', $category)->paginate(10);
$html = view('main', compact('posts'))->render();
return response()->json(['html' => $html]);

And I need to pass the pagination object
. If you do this:
$posts=Post::where('category_id', $category)->paginate(10);
$html = view('main', compact('posts'))->render();
$paginate = $posts->links();
return response()->json(['html' => $html, 'paginate' => $paginate]);

Returns the paginate field empty

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question