use with two static function in laravel eloquent

108 Views Asked by At

i have a table with Branch of business

i have the location of the Branches in the table

and i have a tags for the Branch

how i can do somthing like that:

Branch::withTag('electrician')
->DB::select("SELECT * FROM
                        (SELECT id, business_id, latitude, longitude, (3959 * acos(cos(radians('$lat')) * cos(radians(latitude)) *
                        cos(radians(longitude) - radians('$lng')) +
                        sin(radians('$lat')) * sin(radians(latitude))))
                        AS distance
                        FROM MySite.branches) AS distances

                    WHERE distance < '$max_distance' * 1.609344
                    ORDER BY distance;");

its not work i try to show only the branches Around the loction :latitude, longitude only with the Tags that igive in the start

how i get the Branch with the tag i whant and after that do only in the Result the location order ?

thanks :)

1

There are 1 best solutions below

1
On

In PHP you can't use two static functions in the same command. Answering your question: why don't you union the queries? select() is a Laravel Query Builder

Branch::withTag('electrician')->select("your query here");