使用查询作用域后 子查询无法合并绑定(mergeBindings)
public function apply(Builder $builder, Model $model)
{
$builder->where(DB::raw('LEFT(sampleno,1)'), '<>', 'T')->whereIn('sjsdm',['018','019']);
}
后面的
$sub = $model->whereRaw('yp_lx is not null')->select('yp_lx','styleno')->groupBy('yp_lx','styleno');
$count = DB::table( DB::raw("({$sub->toSql()}) as sub") )
->mergeBindings($sub->getQuery())
->count();
生成sql 里面的参数依旧被 "?" 代替
解决办法
$sub = $model->withoutGlobalScope(AgeScope::class)->where(DB::raw('LEFT(sampleno,1)'), '<>', 'T')->whereIn('sjsdm',['018','019'])->whereRaw('yp_lx is not null')->select('yp_lx','styleno')->groupBy('yp_lx','styleno');
$count = DB::table( DB::raw("({$sub->toSql()}) as sub") )
->mergeBindings($sub->getQuery())
->count();
mark