/** * Search events. * * @param Request $request * @return \Illuminate\View\View */ public function events(Request $request) { $ip = $request->ip(); $ip = '73.85.49.134'; $geolocation = $this->ipGeolocator->ipToGeolocation($ip); $perPage = 4; $defaultDistance = 25; $input = $request->only(['keyword', 'distance', 'lat', 'lng', 'city', 'type']); $input['distance'] = $input['distance'] ?: $defaultDistance; if (!$input['city'] && $geolocation) { $input['lat'] = $geolocation['lat']; $input['lng'] = $geolocation['lng']; $input['city'] = $geolocation['city']; } $events = Event::query()->filterActive()->filterUpcoming()->orderBySoonest(); if ($input['keyword']) { $events->filterKeyword($input['keyword']); } if ($input['distance'] && is_numeric($input['distance'])) { $events->filterNearby($input['lat'], $input['lng'], $input['distance']); } if ($input['type']) { $events->filterTypes($input['type']); } $events = $events->paginate($perPage); $events->appends($input); return view('search.events.result', compact('events', 'input')); }
/** * Show the home page. * * @param Request $request * @return \Illuminate\View\View */ public function index(Request $request) { $ip = $request->ip(); $ip = '73.85.49.134'; $input = ['keyword' => '', 'distance' => 25, 'lat' => '', 'lng' => '', 'city' => '']; if ($geolocation = $this->ipGeolocator->ipToGeolocation($ip)) { $input['city'] = $geolocation['city']; $input['lat'] = $geolocation['lat']; $input['lng'] = $geolocation['lng']; } $events = Event::filterNearby($input['lat'], $input['lng'], $input['distance'])->filterActive()->filterUpcoming()->limit(5)->orderBySoonest()->get(); return view('home.index', compact('events', 'input')); }