What you do is absolutely fine if you want to get an instance of the last item in the collection.
In addition, in Laravel 5.3 you can use the $loop
variable, which allows you to get boolean for the last iteration $loop->last
or get the current iteration index $loop->iteration
, the total number of entries $loop->count
and a few more loop variable
@foreach ($posts as $post) {{ $post->title }} ({{ $loop->iteration }} of {{ $loop->count }}) @endforeach
source share