Solution:
$posts = Post::all(); // returns a collection
You want
$posts = Post::all()->toArray();
You can then call current($posts)
or next($posts)
or prev($posts)
or end($posts)
.
But as you have a collection, you could always use laravel’s collection methods such as first
, last
, each
, filter
, map
, reduce
etc.
https://laravel.com/docs/5.4/eloquent-collections#available-methods