I am building a reversed pagination from a one to many relationship
1 user has many photos
Currently the ID's are coming out Page 1 = 10, 9, 8... Page 2 = 19, 18, 17
How can I make page 1 the most recent = 19, 18, 17... and page 2 = 10, 9, 8...?
In my blade file where the photos are being displayed I am looping through all of the users photos to display them
@foreach($user->photos()->paginate(10)->reverse() as $photo)
and in the same blade file I am building the pagination list
@if($user->photos->count() > 10)
<!-- incl pagination -->
{{ $photos->links() }}
<hr>
@endif
In my controller I am passing through the user and their photos
Unfrotunately orderBy('created_at', 'desc'); or 'asc' doesn't work either.
public function getProfile() {
$user = Auth::user();
$photos = Photo::orderBy('user_id', $user->id)->paginate(10);
return view('user.profile', ['user' => $user, 'photos' => $photos]);
}
Hope someone can help,
Thanks