Reverse the order on Foreach of a Paginator

Submitted by diegofelix - 3 years ago

Sometimes you want to paginate a table in an order, but when showing the items you need to reverse the order. Using the array_reverse on Paginator wont work, but if you use the getItems() its possible.

@foreach (array_reverse($products->getItems()) as $product)
    
    {{ $product->name }}

@endforeach

Ads cover the costs of maintaining Laravel-tricks

comments powered by Disqus

Ads cover the costs of maintaining Laravel-tricks