Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将mysql查询转换为雄辩的查询生成器_Php_Mysql_Laravel_Eloquent - Fatal编程技术网

Php 将mysql查询转换为雄辩的查询生成器

Php 将mysql查询转换为雄辩的查询生成器,php,mysql,laravel,eloquent,Php,Mysql,Laravel,Eloquent,所以我在Laravel Elount query builder中编写mysql查询时遇到了麻烦。这是mysql查询 SELECT a.Location, a.AptDate, a.AptTime, IF(a.AptStatus = 3, 500, AptLength) AptLength, a.AptStatus, o.opname, a.OperatoryNum FROM schedules a LEFT JOIN ops o ON a.Location = o.location AND (

所以我在Laravel Elount query builder中编写mysql查询时遇到了麻烦。这是mysql查询

SELECT a.Location, a.AptDate, a.AptTime, IF(a.AptStatus = 3, 500, AptLength) AptLength,
a.AptStatus, o.opname, a.OperatoryNum
FROM schedules a
LEFT JOIN ops o ON a.Location = o.location AND (a.Operatory = o.opname OR a.AptStatus = 3)
这就是我到目前为止所做的,但它不起作用,因为我得到了一个错误,我的语法有一个错误

$arrAppointment = DB::table('schedules a')
                                ->select("a.Location, a.AptDate, a.AptTime",
                                    DB::raw('IF(a.AptStatus = 3, 500, AptLength)'), 'AptLength,a.AptStatus, o.opname, a.OperatoryNum' )
                                ->leftJoin('ops o', 'a.Location = o,location AND a.Operatory = o.opname or a.AptStatus = 3')

你知道我哪里出错了吗?

我看到左连接上有语法错误(
o,location
=>
o.location
),但无论如何,请尝试以下操作:

$arrAppointment = DB::table('schedules a')
->selectRaw('a.Location, a.AptDate, a.AptTime, IF(a.AptStatus = 3, 500, AptLength) AptLength,a.AptStatus, o.opname, a.OperatoryNum' )
->leftJoin(DB::raw('ops as o'), function($join) {
    $join->on('a.Location', '=', 'o.location');
    $join->where(function($q) {
        $q->where('a.Operatory','=','o.opname');
        $q->orWhere('a.AptStatus','=', 3);
    });
});