0

I have three tables

institutes
id,name,email,etc...

reviews
id,institute_id,rating,description,etc...

courses
id,institute_id,name,etc...

coupons
id,course_id,code,discount,etc...

Institute extends Model{
    public function reviews(){
        return $this->hasMany(Review:class);
    }
}

I do have all the necessary relations setup.

  1. Sort institutes by popularity, popularity here means just the number of reviews, I have done the rest calculations.

  2. Sort by discount, ascending or descending.

What approaches should I use? I would prefer eloquent way. Any help would be of great help.

Jagadesha NH
  • 2,529
  • 2
  • 23
  • 41
  • Possible duplicate https://stackoverflow.com/questions/23530051/laravel-eloquent-sort-by-relation-table-column – Desh901 Aug 25 '17 at 15:51
  • Everything you need to know to answer this question [can be found here](https://laravel.com/docs/5.4/eloquent-relationships#querying-relations) – Taylor Foster Aug 25 '17 at 17:38

0 Answers0