PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 19, 2022

[FIXED] Laravel 5: not able to use pagination, I get error "Call to undefined method Illuminate\Database\Eloquent\Collection::render()"

 January 19, 2022     laravel-5, pagination, php     No comments   

Issue

I am quite new to Laravel and started to play around with L5 and tried to paginate my data (from my HomeController method):

someMethod(){
   ...
   $messages = Message::paginate(50)->sortByDesc('timestamp');
   return view('home', ['messages' => $messages]);
}

in my home.blade view:

...
                        <div class="list-group">
                            @foreach($messages as $message)
                                @if(!$message->processed)
                                ...
                                @endif
                            @endforeach
                        </div>
                        {!! $messages->render() !!}
...

I get the error below:

FatalErrorException in b706d42af4b0adc08aee8abb2fdf4ba9 line 105:
Call to undefined method Illuminate\Database\Eloquent\Collection::render()
in b706d42af4b0adc08aee8abb2fdf4ba9 line 105

I followed the logic from the Pagination doc page : https://laravel.com/docs/5.1/pagination#basic-usage and https://laravel.com/docs/5.1/pagination#displaying-results-in-a-view


Solution

You have an error in your code. Try this:

$messages = Message::orderBy('timestamp', 'desc')->paginate(50);



Answered By - Alexey Mezenin
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing