Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
How to fetch data using AJAX LARAVEL with pagination

can you suggest a way on how can I fetch a data using AJAX LARAVEL with pagination? I already have a fetch function using AJAX and it is already working, but I wanted to add a pagination. Thank you in advance.

This is my controller

public function fetchAllCustomer()
{

    $customers = Customer::all();
    return response()->json([
        'customers'=>$customers,
    ]);
}

This is my AJAX function

function fetchstudent() {
      $.ajax({
          type: "GET",
          url: "/fetch-customer",
          dataType: "json",
          success: function (response) {
              // console.log(response);
              $('tbody').html("");
              $.each(response.customers, function (key, item) {
                  $('tbody').append('<tr>\
                      <td>' + item.first_name + '</td>\
                      <td><button type="button" value="' + item.id + '" class="btn btn-primary editbtn btn-sm">Edit</button></td>\
                      <td><button type="button" value="' + item.id + '" class="btn btn-danger deletebtn btn-sm">Delete</button></td>\
                  \</tr>');
              });
          }
      });
  }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Laravel Docs - Pagination using Eloquent: https://laravel.com/docs/9.x/pagination#paginating-eloquent-results

Instead of:

public function fetchAllCustomer()
{

$customers = Customer::all();
return response()->json([
    'customers'=>$customers,
]);
}

Should be:

    public function fetchAllCustomer()
{
    $customers = Customer::paginate(15);
    // handle your pagination links in AJAX
    $paginationLinks = (string) $customers->links();
    return response()->json([
        'customers'  =>$customers,
        'pagination' => $paginationLinks
    ]);
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda