Search Posts

Author: D Coder

complex join clause in Laravel Eloquoent

I have three tables: A, B & C. Table A: id B_id value Table B: id C_id company Table C: id state Now, I want to do this following query using Eloquoent relationship. select * from A, B, C where A.B_id = and B.C_id = and C.state = 1 I decalred the relationships in each model and performed and following query: A::with([‘b’ => function($query) { $query->with([‘C’=> function($q) { $q->where(‘state’, 1); }]); }])->get(); But, […]

Sort MySQL records according to co-ordinates

I have a MySQL Table where there are three columns: lat, lon and ID Now as Input I want user to give a pair of Lat & long. In return, I want to show the sorted rows from closest to farthest. Now, one solution of this problem is, fetch all entries in an array, make a temp array, calculate distance for each item using haversine formula, push to the temp array, and finally perform any […]