public function cronWeather() { Weather::truncate(); $hoteluri = Hoteluri::all(); foreach ($hoteluri as $hotel) { $file = "http://api.yr.no/weatherapi/locationforecast/1.9/?lat={$hotel->Latitude};lon={$hotel->Longitude};msl=70"; $xml = new SimpleXMLElement($file, null, TRUE); $temp = $xml->product->time; foreach ($temp as $xml_time) { foreach ($xml_time->location as $xml_loc) { if ($xml_loc->minTemperature && $xml_loc->maxTemperature && $xml_loc->symbol) { $mintemp = $xml_loc->minTemperature->attributes()->value; $maxtemp = $xml_loc->maxTemperature->attributes()->value; $array_min = array_filter(preg_split("(T|Z)", $xml_time->attributes()->from)) + ['2' => (string) $mintemp]; $array_max = array_filter(preg_split("(T|Z)", $xml_time->attributes()->to)) + ['2' => (string) $maxtemp]; $icon = "http://api.yr.no/weatherapi/weathericon/1.1/?symbol=" . $xml_loc->symbol->attributes()->number . ";is_night=1;content_type=image/png"; $array = ['HotelID' => $hotel->id, 'FromDate' => $array_min[0], 'FromHour' => $array_min[1], 'MinDegrees' => $array_min[2], 'ToDate' => $array_max[0], 'ToHour' => $array_max[1], 'MaxDegrees' => $array_max[2], 'Logo' => $xml_loc->symbol->attributes()->number]; Weather::create($array); } } } } }