当我在我的过滤器查询中没有传递orWhereBetween条件但是当我传递时,一切都很好 - > orWhereBet在查询结果之间没有任何意义..
希望有人可以帮助我,并且可以在我的orWhereBetween中看到问题出在哪里,非常感谢。
$ query = Amende :: query();
$filters = [
'structure_id' => 'structure_id',
'equipe_id' => 'equipe_id',
'bareme_amende_id' => 'bareme_amende_id',
'saison_id' => 'saison_id' ,
'dt_min' => 'dt_amende' ,
'dt_max' => 'dt_amende',
'etat_paiement' => 'etat_paiement',
'bl_comptabilite' => 'bl_comptabilite',
];
$dt_min = $request->input('dt_min');
$dt_min = Carbon::parse($dt_min)->format('Y-m-d');
$dt_max = $request->input('dt_max');
$dt_max = Carbon::parse($dt_max)->format('Y-m-d');
foreach ($filters as $key => $column) {
$query->when($request->has($key), function ($query, $value) use ($column,$key, $request , $dt_min , $dt_max) {
$query->where($column, $request->$key)
->orWhere(function ($query) use ($dt_min , $dt_max){
$query->whereBetween('dt_amende' , [$dt_min , $dt_max]);
});
});
}
$amendes = $query->paginate(10);
答案 0 :(得分:1)
try this one...
$dt = array($dt_min , $dt_max);
->orWhere(function ($query) use ($dt){
$query->whereBetween('dt_amende' , [$dt[0] , $dt[1]]);
});