return $this->hasMany(Question::class, 'courses.course_id')
->join('modules', 'courses.id', '=', 'modules.course_id')
->join('lessons', 'modules.id', '=', 'lessons.module_id')
->join('tests', 'tests.lesson_id', '=', 'lessons.id')
->join('questions', 'questions.test_id', '=', 'tests.id');
join($table, $first, $operator = null, $second = null, $type = 'inner', $where = false)
return $this->hasMany(Question::class, 'test_id')
->join('modules', 'courses.id', '=', 'modules.course_id')
->join('lessons', 'modules.id', '=', 'lessons.module_id')
->join('tests', 'tests.lesson_id', '=', 'lessons.id')
->join('questions', 'questions.test_id', '=', 'tests.id');
select urlId, count(*) from event group by urlId;
select sum(distance) from (select
ST_Distance_Sphere(
point(points.longtitude, points.latitude),
point(
lead(longtitude) over( order by points.date),
lead(latitude) over( order by points.date)
)
) as distance
from points
where date between '2022-07-01 00:00:00' and '2022-07-05 00:00:00'
order by date asc) as t;
select * from questions;
И дальше идем
select * from questions
join test_quesion on test_question.question_id = questions.id
join tests on tests.id = test_question.test_id
join lessons on lessons.id = tests.lesson_id
join modules on modules.id = lessons.module_id;
А таблица courses нам уже нахрен не нужна - ибо у нас в таблице modules есть поле course_id
Ну собственно я исправил в ответе.