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

223
Visualizações
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 à 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