Order JSON column attribute

With Eloquent you can order results by a JSON column attribute

1// JSON column example:
2// bikes.settings = {"is_retired": false}
3$bikes = Bike::where('athlete_id', $this->athleteId)
4 ->orderBy('name')
5 ->orderByDesc('settings->is_retired')
6 ->get();

Tip given by @brbcoding

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord