2 回答
TA贡献1818条经验 获得超7个赞
您可以将回调传递where给 group or。
//quick example of Parameter Grouping:
$query = Product::query();
$query->where(function ($query) use ($search_parameters){
$query->whereIn('marketplace_id', $search_parameters['marketplaces'])->orWhereIn('conta_id', $search_parameters['account']);
})->where("titulo", 'ilike', '%' . $search_parameters['titulo'] . '%');
请阅读 DB Query Builder Laravel: DOCS
TA贡献1725条经验 获得超7个赞
答案指明了方向。我能够查看是否传递了参数并动态添加条件。
$query->where(function ($query) use ($parametros_pesquisa){
if($parametros_pesquisa['marketplaces'] !== null && $parametros_pesquisa['accounts'] !== null){
$query->whereIn('marketplace_id', json_decode( $parametros_pesquisa['marketplaces']))->orWhereIn('conta_id', json_decode( $parametros_pesquisa['accounts']));
}elseif($parametros_pesquisa['marketplaces'] !== null){
$query->whereIn('marketplace_id', json_decode( $parametros_pesquisa['marketplaces']));
}elseif($parametros_pesquisa['accounts'] !== null){
$query->whereIn('conta_id', json_decode( $parametros_pesquisa['accounts']));
}
});
- 2 回答
- 0 关注
- 119 浏览
添加回答
举报