1
I have a table called "tabela_precos", with the following structure:
categoria_veiculo_id | valor | preco_min | preco_max | tipo_veiculo
22 77,70 0 2500 carros
22 30,35 15000 20000 carros
When I run the following query in phpmyadmin, the return is correct and only brings a result (the register with a value of 30,35):
select * from `tabela_precos` where `tipo_veiculo` = "carros" and `categoria_veiculo_id` = 22 and 15000 between preco_min and preco_max ;
but when I run this on Laravel, it returns me the two records (even using limit 1
or first()
, code:
$query = TabelaPreco::whereRaw('? between preco_min and preco_max', [$request->preco_fipe])
->where('categoria_veiculo_id', $request->categoria_veiculo_id)
->where('tipo_veiculo', $request->tipo_veiculo);
this data comes from a form, and even if I put the data directly into the code, the same two records are returned.
I’ve already given one toSql()
and the query is exactly the same that I ran directly on phpmyadmin
I know this is probably something very silly, but I couldn’t understand why it happens.
I didn’t understand why my answer was negative, no one could answer, it’s a subtle detail but difficult to understand...
– Thiago