Laravel: Inner join QueryException


Laravel: Inner join QueryException

我正在尝试在Laravel中的表之间执行join。但是,我在加载页面时收到此消息:

QueryException in Connection.php line 651:

这是查询:

$patches = DB::table('or_patches')
    ->join('or_clients', function($join) use($authid)
    {
        $join->on('or_patches.client_id', '=', 'or_clients.id')
        >where('or_clients.customer_id'. '=', $authid);
    })
    ->get();

如果我删除use(),并在静态值上构建"where",它也不起作用。

详细错误:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an 
error in your SQL syntax; check the manual that corresponds to your 
MySQL server version for the right syntax to use near '1 ?' at line 1 
(SQL: select * from `or_patches` inner join `or_clients` on 
`or_patches`.`client_id` = `or_clients`.`id` and 
`or_clients`.`customer_id=` 1 )

有谁知道为什么?我也尝试使用left joins,但没有成功。

更新:尝试将 where 子句中的"." 更改为","。这解决了问题。谢谢@AlexRussel。

从 SQL

错误的外观(SQL ...`or_clients.customer_id=` 1 问题)来看,您从附加到字段名称的查询中获得=。看看代码,它看起来就像一个简单的拼写错误,您在方法调用中使用.而不是,,从而将=连接到字段:

>where('or_clients.customer_id'. '=', $authid);

应该是:

->where('or_clients.customer_id', '=', $authid);