/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // Retreiving from the db without cashing may slow down the db server, so // it's better to use caching function in Laravel to avoid that //$vehicles = Vehicle::all(); $tableName = 'vehicles'; $interval = 15 / 60; // 15 seconds $results = Cache::remember($tableName, $interval, function () { return Vehicle::simplePaginate(5); }); return response()->json(['count' => $results->count(), 'currentPage' => $results->currentPage(), 'hasMorePages' => $results->hasMorePages(), 'perPage' => $results->perPage(), 'nextUrl' => $results->nextPageUrl(), 'prevUrl' => $results->previousPageUrl(), 'data' => $results->items()], 200); }