Laravel, problem with Float fields

Asked

Viewed 61 times

0

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

my select is 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 presents 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 Round. with that select does not work. I copied this query and took the ` then the bank presents the results without problem.

1 answer

0

That 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();
  • Unfortunately he presented the same result =/, but thanks anyway.

  • Strange try to give a DD(select) and see if the string is being mounted correctly

  • Yes, by doing the DD($select) it showed correctly. only by calling the function even it changes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.