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
You have an error in your code. Try this:
$messages = Message::orderBy('timestamp', 'desc')->paginate(50);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.