Laravel5.4:在LaravelEloquent中转换原始sql查询

jckbn6z7  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(537)

我正试图重写这个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

dldeef67

dldeef671#

使用 where() :

$join->where('project_progress.id', '=', function ($query) {

相关问题