place->weathers() ->orderBy('created_at', 'desc') ->first(); // only get weather data if weather is either not existant or if is // more than 6h old if (is_null($weather) || ! $weather->created_at->between(now()->subHours(6), now())) { self::callWeatherAPI($address); } return $weather; } /** * Make the call to the weather service. * * @param Address $address */ private static function callWeatherAPI(Address $address): void { $jobs = []; if (is_null($address->place->latitude) && config('monica.enable_geolocation') && ! is_null(config('monica.location_iq_api_key'))) { $jobs[] = new GetGPSCoordinate($address->place); } if (config('monica.enable_weather') && ! is_null(config('monica.weatherapi_key'))) { $jobs[] = new GetWeatherInformation($address->place); } Bus::batch($jobs) ->dispatch(); } }