我有一个定义的变量,$ siteID。但是,Laravel在查询中丢失了它的值,并且出现错误“未定义变量:siteID”
$directoryExternalStats = DB::table('directories')
->leftJoin('citations', function($join)
{
$join->on('directories.id', '=', 'citations.directory_id')
->where( function($dirindustries) use($siteID){
$dirindustries->whereRaw('id NOT IN (SELECT DISTINCT directory_model_id FROM directory_model_industry)')
->orWhereRaw('id IN
(SELECT directory_model_id FROM directory_model_industry
(SELECT industry_id FROM industry_site WHERE site_id = '. $siteID .')
;
});
});
我正在声明要在查询中使用的变量,但是Laravel无法识别它。更改语法以使用占位符无济于事。
我尝试在第一个闭包中包含变量:
$directoryExternalStats = DB::table('directories')
->leftJoin('citations', function($join) use($siteID)
{
在第二个关闭处:
$join->on('directories.id', '=', 'citations.directory_id')
->where( function($dirindustries) use($siteID){
并在两个闭包中:
$directoryExternalStats = DB::table('directories')
->leftJoin('citations', function($join) use($siteID)
{
$join->on('directories.id', '=', 'citations.directory_id')
->where( function($dirindustries) use($siteID){
但是无论如何我都会得到一个错误。在Jonas的帮助下,我注意到在两个闭包中都包含变量会导致不同错误消息:“缺少Illuminate \ Database \ Query \ JoinClause :: where()的参数2”
这是Laravel错误的一个实例吗? https://github.com/laravel/framework/issues/18952 要么 https://github.com/laravel/framework/issues/5992 要么 https://github.com/laravel/framework/issues/5466
还是我只是在某个地方犯了语法错误?