It is achieved in simple one step process like below by modifying index() method in PollController.php
public function index() { //dd(request('search_title')); $polls = Poll::paginate(5); return response()->json($polls,200); }
Please note, first of all number of data that is mentioned in the parameter of paginate() method will be returned under "data" json array response.
Then it returns a few more metadata such as current_page, last_page, first_page_url, last_page_url, links etc so that these can be used
for processing of front end pages based on these metadata values in the main application.