Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

269
Visualizações
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>');
              });
          }
      });
  }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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
    ]);
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda