Example #1
0
 public function newPosts(Request $request)
 {
     $lattitude = $request->input('lattitude');
     $longitude = $request->input('longitude');
     $radius = 10;
     $posts = Location::select(DB::raw("locations.post_id,\n                               ( 6371 * acos( cos( radians(?) ) *\n                                 cos( radians( lattitude ) )\n                                 * cos( radians( longitude ) - radians(?)\n                                 ) + sin( radians(?) ) *\n                                 sin( radians( lattitude ) ) )\n                               ) AS distance, posts.message, posts.user_id, users.id, users.name, users.user_name"))->join('posts', 'posts.id', '=', 'locations.post_id')->join('users', 'users.id', '=', 'posts.user_id')->having("distance", "<", $radius)->orderBy("posts.created_at", 'desc')->setBindings([$lattitude, $longitude, $lattitude])->distinct()->get();
     return response()->json($posts);
 }
 public function mapListings()
 {
     $listingInfo = Listing_Info::where('is_active', '=', 1)->get();
     $num = Listing_Info::where('is_active', '=', 1)->count();
     $location = Location::select('city', 'country')->groupBy('city')->get();
     if (Auth::check()) {
         $savedSearch = Saved_Search::where('user_id', '=', Auth::user()->user_id)->get();
     } else {
         $savedSearch = null;
     }
     return view('mapListing', compact('listingInfo', 'location', 'savedSearch'), compact('num'));
 }