First of all i don't get it why u don't want to do the order in the select query, in my opinion it is more neat and has a better performance then sorting in php. But since you don't want that, well i see two ways : 1- You sort your collection based on the id value : may be this could help http://www.mabishu.com/blog/2011/02/03/sort-an-array-of-objects-by-one-of-the-object-property-with-php/ but in your case you will be iterating a collection of objects and not an array of objects.
2- Use the toArray() method to transform everything to array and the you can use the array sort functions http://php.net/manual/fr/ref.array.php
In the end as you can see doing the sorting in php is a mess compared to doing it in sql ORDER BY id ASC (or the equivalent in Query Builder order() method)
Or simply:
<h1>{{ $post->title }}</h1>
@foreach($post->comments->reverse() as $comment)
{{ $comment->title }}
@endforeach
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community