如何將mysql查詢轉換爲laravel查詢?這是查詢將mysql子查詢轉換爲Laravel
SELECT
users.first_name,
users.id AS uid,
(
SELECT
COUNT(vpl_submissions.accept)
FROM
vpl_submissions
INNER JOIN vpl ON vpl_submissions.vpl = vpl.id
WHERE vpl.courseid = 2
AND vpl_submissions.accept = 1
AND vpl_submissions.userid = uid
) AS completed
FROM
users
INNER JOIN course_enroles ON users.id = course_enroles.user_id
WHERE course_enroles.course_id = 2
你有沒有看過使用'Eloquent'? https://laracasts.com/series/laravel-from-scratch-2017/episodes/7 https://laracasts.com/series/laravel-from-scratch-2017/episodes/15 –