A
A
Anatoly2017-11-17 07:44:36
ORM
Anatoly, 2017-11-17 07:44:36

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; }
    }
}

When I do
dd($deposits->toSql());
a Show query in sql format and insert it into the MySQL manager, it gives the correct result.
And when I deduce That so deduces more results. Why is this happening?
$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 question

Ask a Question

731 491 924 answers to any question