Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
Cómo obtener datos usando AJAX LARAVEL con paginación

¿Puede sugerir una forma de obtener datos usando AJAX LARAVEL con paginación? Ya tengo una función de búsqueda usando AJAX y ya está funcionando, pero quería agregar una paginación. Gracias de antemano.

este es mi controlador

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

Esta es mi función AJAX

 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 answers
Answer question

0

Laravel Docs - Paginación usando Eloquent: https://laravel.com/docs/9.x/pagination#paginating-eloquent-results

En vez de:

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

Debiera ser:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!