Laravel Query Builder
Raw SQL
-- Course lesson by course
select count(lession_id) from h247app_lessions where topic_id in
(
select topic_id from h247app_topics where course_id in
(select course_id from h247app_courses where subject_code='tieng-anh')
)
Laravel Query Builder
/**
* * getLessonsCount.
*
* @return void
*/
public function getLessonsCount()
{
return DB::table('h247app_lessions')
->select(DB::raw('count(*)'))
->whereIn('topic_id', function ($q) {
$q->select('topic_id')->from('h247app_topics')
->whereIn('course_id', function ($q) {
$q->select('course_id')->from('h247app_courses')->where('subject_code', $this->subjectCode);
});
})
->count();
}