条件组合查询问题

DB::table('users')
->where('name', '=', 'John')
->orWhere(function($query)
{
$query->where('votes', '>', 100)
->where('title', '<>', 'Admin');
})
->get();

我想在orWhere的function中使用自己的参数该怎么写?
我这样写报错了:
$roles = DB::table('suppliers')->lists('city');
$provinces = DB::table('locations')
->where(function($query,$roles)
{
$query->where('province_id', '=', 0)
->whereIn('id', $roles);
})
->orWhere(function($query,$roles)
{
$query->whereIn('province_id',$roles);
})
->get();

ErrorException

Missing argument 2 for {closure}() (View: /var/www/bcyi/web/app/views/web/suppliers/suppliers.blade.php)
已邀请:

motecshine - 菜鸟

赞同来自: kelson

丢失了一个闭包参数,建议安装 ide_hleper这个包,然后定位代码,看下参数都有那些,具体做了什么

qufo

赞同来自:

$roles = DB::table('suppliers')->lists('city');
$provinces = DB::table('locations')
->where(function($query) use ($roles)  //注意这里
{
$query->where('province_id', '=', 0)
->whereIn('id', $roles);
})
->orWhere(function($query) use ($roles) //以及这里
{
$query->whereIn('province_id',$roles);
})
->get();

这样试一下。

要回复问题请先登录注册