laravel OrderBy on Eloquent whereHas relationship

$users = User::with(['student' => function ($q) {
            $q->orderBy('id', 'desc');
        }]);

3.78
9
Kidus Amare 160 points

                                    $counties = County::whereHas('items', function ($query) {
    $query->where('approved', 1);
})->orderBy('name')->get();

3.78 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
orderby relation laravel eloqunet orderby wherehas laravel laravel query order by relation eloquent whereHas and orderBy laravel order by with relation laravel orderby from relations order by with relationship laravel order by value in whereHas laravel laravel orderby on relationship sort query by relation laravel order by with relation laravel laravel eloquent orderby relationship order by in relation laravel laravel relationship orderby orderby in with relationship laravel order by on relationship eloquent laravel orderby where has laravel order by relationship field then by laravel order by eloquent relationship laravel with order by relation orderby relationship laravel set orderby relationship eloquent eloquent model relationship orderby order by relationship laravel laravel orderby relationship laravel orderby relationship field laravel orderby relation laravel orderBy relation created_at orderBy relation laravel relationship laravel with order by laravel order by relationship laravel eloquent relationships orderby laravel eloquent order by relationship orderby with relationship in laravel eloquent all order by laravel orderby is not working with wherehas order eloquent collection eloquent with relation order by laravel eloquent multiple relationships orderby laravel orderby belongsto relationship orderby laravel where query laravel order by belongsto relationship column order by in laravel eloquent laravel eloquent order by order by eloquent relationship laravel laravel eloquent orderby proximity laravel orderby in wherehas laravel orderby in wheregas order by field eloquent laravel wherehas orderby laravel laravel sortby a wherehas query laravel sort the data on with and wherehas table laravel sort the data on wherehas table laravel orderby and paginate
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source