我在Eloquent中有一个查询,我想按日期过滤,但有一个“WhereHas”或“WhereIn”不再过滤它们。如何解决我的问题?
public static function filterForTransactions(Request $request, MarketAgreement $v_teleco, AgreementEnergia $v_energia) {
$v_teleco = $v_teleco->newQuery();
$v_teleco->where('user_id_inversor', \Auth::user()->id)
->orWhereHas('market_transaction', function($query){
$query->where('user_id_subaccount', \Auth::user()->id);
})
->orWhereIn('user_id', [$ids]);
if ($request->has('from') && $request->has('to') && $request->input('from') != null && $request->input('to') != null) {
$from = \Carbon\Carbon::parse($request->from)
->startOfDay()
->toDateTimeString();
$to = \Carbon\Carbon::parse($request->to)
->endOfDay()
->toDateTimeString();
$v_teleco->whereBetween('created_at', [$from, $to]);
}
return $v_teleco->orderBy('updated_at', 'desc')->get();
}
1条答案
按热度按时间ilmyapht1#
关于你的代码有几件事要提一下
这样它看起来很好,所以如果它仍然不工作,请提供更多的细节