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

163
Views
No puedo limitar mis publicaciones a 10, mi solicitud de Ajax no funciona

No tengo errores, pero mis publicaciones continúan mostrándose por completo cuando me gustaría limitarlas a 10 y tener un botón "más publicaciones". Soy nuevo en el desarrollo de laravel. Realmente bloqueo este problema incluso dándole la vuelta por todos lados.

Qué estoy haciendo mal ? Gracias por tu ayuda !

PostsController

 class PostsController extends Controller { public function index() { $posts = Post::orderBy('created_at', 'desc') ->take(10) ->get(); return view('posts.index', compact('posts')); } public function show(Post $post) { $posts = Post::orderBy('created_at', 'desc') ->take(10) ->get(); return view('posts.show', compact('post')); } public function more(Request $request) { $posts = Post::orderBy('created_at', 'desc') ->take(10) ->offset($request->offset) ->get(); return view('posts._list', compact('posts')); } }

En vistas:

 @section('content') <div class="row d-flex" id="list"> @include('posts._list', ['posts' => $posts]) </div> <div id="wrapper-oldnew"> <div class="oldnew"> <div class="wrapper-oldnew-prev"> <a id="oldnew-prev" data-url="{{ route('ajax.posts.more') }}"></a> </div> </div> </div> @section('scripts') <script> let offset = 10; $('#oldnew-prev').click(function(e) { e.preventDefault(); $.get($(this).data('url'), {offset: offset}) .done(function(rep) { $('#list').append(rep) .find('.col-md-6:nth-last-of-type(-n+10)') .addClass('fadeInUp') .addClass('ftco-animated'); offset = offset + 10; }); }); </script> @endsection
 <!-- Script Axios - Ajax --> <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> <script> const oldnew = document.getElementbyId('oldnew-prev'); oldnew.onclick = function(){ axios.get('traitement.php') .then(function(reponseServeur){ }); } </script>
over 4 years ago · Santiago Trujillo
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!