Laravel, problem with Float fields

0

Hello, I'm using Laravel and I need to do a select in a table, I also create a field that brings the result of a function.

My select looks like this:

return \DB::table("view_pins_ocorrencias")
                ->select("*", "round(geo({$dados->latitude},{$dados->longitude},latitude_ocorrencia,longitude_ocorrencia),2) as distancia")
                ->havingRaw('distancia < 400')
                ->havingRaw('distancia > 0.3')
                ->get();

but it has an error:

 "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'round(geo(float(-46.544233),float(-23.543453),latitude_ocorrencia,longitude_ocorrencia),2)' in 'field list' (SQL: select *, 'round(geo(float(-46'.'544233),float(-23'.'543453),latitude_ocorrencia,longitude_ocorrencia),2)' as 'distancia' from 'view_pins_ocorrencias' having distancia < 400 and distancia > 0.3)"

Basically it adds' (Apostrophe) to the float, getting -14 '.' xxxxxxx and also does it in the Round. so select does not work. I copied this query and took the 'ai the database presents the results without problem.

    
asked by anonymous 17.01.2018 / 17:03

1 answer

0

This should work:

$select = 'round(geo('.$dados->latitude.','.$dados->longitude.',la‌​titude_ocorrencia,lo‌​ngitude_ocorrencia),‌​2) as distancia';

return \DB::table("view_pins_ocorrencias")
                ->select("*", $select)
                ->havingRaw('distancia < 400')
                ->havingRaw('distancia > 0.3')
                ->get();
    
17.01.2018 / 17:25