Equation in laravel where condition

327
June 06, 2017, at 05:59 AM

I have table Item with the following fields(latitude,longitude) and I have a function which has as parameters (lat, lon, radius)

then I want to retrieve data which accept the equation (|lon-longitude|/|lat-latitude|)<= radius

I am using laravel 5.4 like the following:

public function calc($lon, $lat, $radius){
    $result = Item::where()->get();
}

Any help how will the where condition be to do this equation!!

Answer 1

Try this using the whereRaw

public function calc($lon, $lat, $radius){
    $result = Item::whereRaw("abs($lon-longitude)/abs($lat-latitude) <= $radius")->get();
}
Rent Charter Buses Company
READ ALSO
Notice unread messages

Notice unread messages

Im trying to notice the new unreaded messages on my chatI'm using a bundle and I create my own friendlist

401
Symfony3 registering exception listener

Symfony3 registering exception listener

I have a Stripe exception wrapper for all of the exceptions that Stripe might throw based on certain casesI'm trying to register an event listener for that exception being thrown, but it doesn't seem like the listener is ever fired

441
XML error on while loop (php, xml element)

XML error on while loop (php, xml element)

As the title suggests i've had some trouble creating an xml element using phpThe document runs fine without my while loop (loop through mysqli_fetch_assoc and print xml for all results) but when i run it inside the while loop i get the following error

242