我正试图重写这个sql查询,但我被困在这一点上
该查询旨在通过使用子查询将projects表连接到project\u progress表,以便只连接最新的条目
SELECT * FROM projects
JOIN project_progress ON project_progress.id =
(
SELECT id FROM project_progress
WHERE project_progress.project_id = projects.id
ORDER BY project_progress.created_at DESC
LIMIT 1
)
WHERE project_progress.next_action_date < NOW()
AND projects.status != 'Complete'
AND projects.member_id = 1
ORDER BY projects.title ASC
收件人:
$projects = App\Project::where('member_id', 1)
->join('project_progress', function ($join) {
$join->on('project_progress.id', '=', function ($query) {
$query->select('project_progress.id')
->from('project_progress')
->where('project_progress.project_id', 'projects.id')
->orderBy('project_progress.created_at', 'desc')
->limit(1);
});
})
->where('project_progress.next_action_date', '<', Carbon\Carbon::now())
->notCompleted()
->orderBy('projects.project_title', 'asc')
->get();
我想这行有点不对劲,但我不知道怎么写
$join->on('project_progress.id', '=', function ($query) {
errorexception(e\u error)strtolower()期望参数1是字符串,object given\vendor\laravel\framework\src\illuminate\database\grammar.php
1条答案
按热度按时间dldeef671#
使用
where()
: