Any examples of what is not working? Maybe this might work:
DB::table('vouchers')
->select(DB::raw('voucher_id, ( 6371 * acos ( cos( radians(3.076559) ) * cos( radians( users.lat ) ) * cos( radians( users.lng ) - radians(101.644432) ) + sin( radians(3.076559) ) * sin( radians( users.lat ) ) ) AS distance'))
->join('users', 'users.user_id', '=','vouchers.user_id')
->having('distance', '<', '25')
->orderBy('distance')
->take(20)
->get();
My fault! I tried the query almost same like yours yesterday, I try it today again and I only found I accidentally deleted a closing parentheses before 'AS distance'.
Anyway, after add back the closing parentheses, your solution worked very nice! Thank you so much pickupman. =)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community