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

165
Views
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
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!