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條經驗 獲得超8個贊
答案指明了方向。我能夠查看是否傳遞了參數并動態添加條件。
$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 關注
- 148 瀏覽
添加回答
舉報