Support the ongoing development of Laravel.io →
Database Eloquent

I have a query with eager loaded results that need to be sorted. I've used similar code in other areas of my site, but for some reason this isn't working.

	$songs = SongGroup::with('song_status')
						->with(array('group_songs' => function($group_song_query)
							{
								$group_song_query->orderBy('sort_no', 'asc');
							}))
						->where('show_id', '=', $id)
						->orderBy('sort_no')
						->get();

The orderBy in $group_song_query isn't sorting. When I say "isn't sorting", I mean that it isn't sorting the integer field called sort_no at all.

Is there something wrong with this that I'm not seeing?

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

jerauf jerauf Joined 16 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.