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

224
Vistas
Unable to limit my posts to 10, My Ajax request doesn't work

I have no errors but yet my posts continue to be displayed entirely when I would like to limit them to 10 and have a "more posts" button. I am new to laravel development. I really block on this problem even by turning it over on all sides.

What am i doing wrong ? Thank you for your help !

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'));
    }
}

In views :

@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
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