Exemple #1
0
 /**
  * List the courses ids.
  *
  * @param $query
  * @return mixed
  */
 public function scopeListCourses($query)
 {
     return $query->lists(Course::table() . "." . Course::primaryKey());
 }
Exemple #2
0
 /**
  * Get all the courses in the database along
  * with the average rating for each course.
  *
  * @param $query
  * @return mixed
  */
 public function scopeRated($query)
 {
     $course_average_rating = CourseLikes::averageRating()->toSql();
     $join_table = \DB::raw("({$course_average_rating}) as {$this->averageRatingTable()}");
     return $query->leftJoin($join_table, function ($join) {
         $join->on(Course::table() . '.' . Course::primaryKey(), '=', $this->averageRatingTable() . '.' . CourseLikes::courseForeignKey());
     });
 }