Laravel Rest API Pagination with Vue.js

Pagination when it comes to rest API can give you a bit of a headache, lucky for us, Laravel comes with it’s own solution for the backend as well as Vue.js

1)In order to get Laravel to make your Rest API results Pagination friendly, you must add this method to your controllers:

->paginate(10); <---It will output 10 results per page

Here is a full example:

public function getReports(Request $request){

$results = Marker::where([['isaccepted','=','3'],['user_id','=',$request->user()->id]])->orderBy('id', 'desc')->paginate(10);
return response()->json(['data' => $results], 200);


2)Your data object will now have extra options as:


3)Your Laravel api route has to be setup this way:

Route::group(['prefix' => 'v1'], function() {
Route::get('getreports', 'Api\ReportsController@getReports');

You will now be able to access the route via:

All you have to do now is receive the data with the extra meta options and use this vue plugin to play with your paginated data(unless you prefer to code your own solution)

If this short tutorial helped you, please leave me a message





















As an Amazon Associate I earn from qualifying purchases. This post may contain affiliate links which means I may receive a commission for purchases made through links.