Answer the question
In order to leave comments, you need to log in
Why is whereHas not working correctly?
Good afternoon!
The essence of the problem is that when selecting deposits with a term in the range from and to:
$deposits = new Deposits;
/* тут еще код */
$deposits = $deposits->whereHas('currencies', function ($query) use ($post) {
switch ($post['term']) {
case 1: { $query->where('term_ot', '<=', 1); break; }
case 2: { $query->where('term_ot', '>=', 1)->where('term_ot', '<=', 3); break; }
case 3: { $query->where('term_ot', '>=', 3)->where('term_ot', '<=', 6); break; }
case 4: { $query->where('term_ot', '>=', 6)->where('term_ot', '<=', 9); break; }
case 5: { $query->where('term_ot', '>=', 9)->where('term_ot', '<=', 12); break; }
case 6: { $query->where('term_ot', '>=', 12)->where('term_ot', '<=', 24); break; }
case 999: { $query->where('term_ot', '>=', 24); break; }
}
}
dd($deposits->toSql());
$deposits = $deposits->orderBy('title')->get();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question