Laravel 原始查询在与原始语句连接时给出错误

Laravel Raw Query giving error in join with raw statement

我有两个 tables 用户和 db_ips,我需要用 db_ips table 列 lat lon 将用户的纬度和经度与两位小数点值进行比较,为此,我在 laravel.

中编写了查询

查询

$users = \DB::table('users')
         ->select("id", "latitude", "longitude")
         ->Join('IPAddress AS IP', \DB::raw('ROUND(IP.lat,3)'), '=', \DB::raw('ROUND(users.latitude,3)'))
         ->where('users.login_tries', "=", 0)
         ->where('users.latitude', "<>", "")
         ->whereNotNull('users.latitude')
         ->orderBy("id", "ASC")->limit(100)->get();
return !$users->isEmpty() ? $users : [];

对于两个三位小数的比较,我在连接中使用了 ROUND 方法,但是当我 运行 查询时,我得到以下错误而不是结果

错误

Too few arguments to function Illuminate\Database\Query\Builder::join(), 1 passed in /home/rizwan/php/fayvo/archive/app/Console/Commands/SyncUserLocat
ion.php on line 139 and at least 2 expected

我也尝试原始查询,但在收到 field_list 错误时不知道 column_name

join(string $table, string $first, string|null $operator = null, string|null $second = null, string $type = 'inner', bool $where = false)

根据 join API,它至少需要 2 个参数,因此请像这样更改您的代码:

->Join('IPAddress AS IP', \DB::raw('ROUND(IP.lat,3)'), '=', \DB::raw('ROUND(users.latitude,3)'))