gpt4 book ai didi

php - laravel 原始连接查询

转载 作者:行者123 更新时间:2023-12-02 00:41:20 26 4
gpt4 key购买 nike

我有一个接受原始 where 条件和连接的函数:

query('data',['fieldA','fieldB'], 'fieldA > 10 AND fieldB < 20', 'LEFT JOIN users ON data.user_id = users.id');

function query($table, $keys = [], $where = '', $joins = '') {
$query = DB::table($table)->select($keys);
if(!empty($where)) {
$query=$query->whereRaw($where);
}
if(!empty($joins)) {
$query=$query->?????????????
}
return $query->get();
}

我如何像使用 whereRaw 来处理 where 条件那样,将原始连接与查询构建器一起使用?

最佳答案

没有好闻但工作

    \DB::table('data')->join('user', function($join){
$join->on(\DB::raw('( `data`.`user_id` = `user.id` or (`data`.`user_id` is null and `data`.`other_field` is null)) and 1 '),'=',\DB::raw('1'));
})

关于php - laravel 原始连接查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46566920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com