Mysql JoinClause.php第79行中的InvalidArgumentException:on子句的参数不足
我用laravel做了查询生成器,并在其中使用了多重连接。执行查询时,我得到的错误是on子句的参数不足。 我的查询生成器:Mysql JoinClause.php第79行中的InvalidArgumentException:on子句的参数不足,mysql,laravel,laravel-5,laravel-5.1,Mysql,Laravel,Laravel 5,Laravel 5.1,我用laravel做了查询生成器,并在其中使用了多重连接。执行查询时,我得到的错误是on子句的参数不足。 我的查询生成器: return DB::table('towns_cat_rel') ->join('towns', function ($join) { $join->on('towns_cat_rel.town_id', '=', 'towns.id') ->where('publish', '=', 1); })
return DB::table('towns_cat_rel')
->join('towns', function ($join) {
$join->on('towns_cat_rel.town_id', '=', 'towns.id')
->where('publish', '=', 1);
})
->join('towns_translations', function ($join) {
$join->on('towns_cat_rel.town_id', '=', 'towns_translations.town_id')
->where('locale', '=', \App::getLocale());
})
->join('towns_cat', function ($join) use($categoryID) {
$join->on('towns_cat.id', '=', 'towns_cat_rel.town_cat_id')
->where('towns_cat.id', '=', $categoryID);
})
->join('towns_sub_cat_rel', 'towns_cat_rel.town_id', '=', 'towns_sub_cat_rel.town_id')
->join('towns_sub_cat', function ($join) use($subCategoryID) {
$join->on('towns_sub_cat_rel.town_sub_cat_id', 'towns_sub_cat.id')
->where('towns_sub_cat.id', '=', $subCategoryID);
})
->get();
有人知道为什么会这样吗?对不起,伙计们!我忘记了上次加入('towns\u sub\u cat\u rel.town\u sub\u cat\u id'、'='、'towns\u sub\u cat.id')时的
现在它工作得很好 我使用的是laravel5.2,由于上面的代码,我遇到了上面的错误消息,我用这段代码解决了这个问题,您可以根据需要修改
DB::table('users')
->join('contacts', function ($join) {
$join->on('users.id', '=', 'contacts.user_id')->orOn(...);
})
->get();
Add=在ON方法的第二个参数中,或跟随链接