Im having a hard time converting this raw MySQL query in phpmyadmin. I want to convert it to laravel’s query builder or eloquent. I already configured the relationships in the model. Can someone convert my query to querybuilder and eloquent? I tried some converter but it doesnt work for me. Thanks
Raw Query
SELECT count( * ) FROM users u, sectionschedules s, notes n
WHERE u.parent_id=26
AND u.section_id=s.section_id
AND s.id = n.schedule_id;
Query I tried
$notes = DB::table('notes')
->join('users', 'users.section_id', '=', 'notes.section_id')
->join('sections','sections.section_id', '=', 'sectionschedules.section_id')
->join('sectionschedules', 'sectionschedules.id','=','notes.schedule_id')
->where('user.parent_id', '=', 26)
->count();
Error I got
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user.parent_id' in 'where clause
2
Answers
Try
Users.parent id as defined not user.parent_id