/** * Display a listing of the resource. * * @return Response */ public function index() { $makers = Cache::remember('makers', 15 / 60, function () { return Maker::simplePaginate(15); }); return response()->json(['next' => $makers->nextPageUrl(), 'previous' => $makers->previousPageUrl(), 'data' => $makers->items()], 200); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // $makers = Maker::all(); $makers = Maker::simplePaginate(15); if (!$makers) { return response()->json(['message' => 'No makers', 'code' => 404], 404); } // return response()->json(['data' => $maker], 200); return response()->json(['data' => $makers->items(), 'previous' => $makers->previousPageUrl(), 'next' => $makers->nextPageUrl()], 200); }
/** * Display a listing of the resource. * * @return Response */ public function index(Request $request) { $page = 0; if ($request->has('page')) { $page = $request->get('page'); } $makers = Cache::remember("makers{$page}", 15 / 60, function () { return Maker::simplePaginate(10); }); return response()->json(['next' => $makers->nextPageUrl(), 'previous' => $makers->previousPageUrl(), 'data' => $makers->items()], 200); }
/** * Display a listing of the resource. * * @return Response */ public function index(Request $request) { //Incluye caché y paginación por si es necesario implementarlo $page = 1; if ($request->get('page')) { $page = $request->get('page'); } $makers = Cache::remember("makers{$page}", 15 / 60, function () { return Maker::simplePaginate(10); }); return response()->json(['next' => $makers->nextPageUrl(), 'previous' => $makers->previousPageUrl(), 'data' => $makers->items()], 200); }
/** * 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 //$makers = Maker::all(); $tableName = 'makers'; $interval = 15 / 60; // 15 seconds $results = Cache::remember($tableName, $interval, function () { return Maker::simplePaginate(15); }); 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); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $makers = Maker::simplePaginate(15); return response()->json(['data' => $makers->items(), 'pagination' => ['prev' => $makers->previousPageUrl(), 'next' => $makers->nextPageUrl()]], 200); }