public function store(Request $request) { $city = $request->input('town'); $response = json_decode(file_get_contents('http://api.openweathermap.org/data/2.5/forecast?q=' . $city . '&mode=json&appid=f84ba1064b0ae65792326548686f361c'), true); // print_r($response); $id = $response['city']['id']; $name = $response['city']['name']; $validator = Validator::make($request->all(), ['town' => 'required|unique:towns,town']); if ($validator->fails()) { return redirect('')->withErrors($validator)->withInput(); } $town = new Town(); $town->town = $name; $town->id = $id; $town->save(); for ($i = 0; $i < sizeof($response['list']); $i++) { $date = date("Y-m-d H:i:s", $response['list'][$i]['dt']); $temp_min = $response['list'][$i]['main']['temp_min']; $temp_max = $response['list'][$i]['main']['temp_max']; $temp_min = round($temp_min - 273.15); $temp_max = round($temp_max - 273.15); $weather = new Weather(); $weather->town_id = $id; $weather->temp_min = $temp_min; $weather->temp_max = $temp_max; $weather->kuupaev = $date; $weather->save(); } return redirect()->action('WeatherController@index'); }
public function getTowns(Request $request, $id) { if ($request->ajax()) { $towns = Town::towns($id); return response()->json($towns); } }
public function store(Request $request) { $city = $request->input('town'); $response = json_decode(file_get_contents('http://api.openweathermap.org/data/2.5/forecast?q=' . $city . '&mode=json&appid=f84ba1064b0ae65792326548686f361c'), true); // print_r($response); $id = $response['city']['id']; $name = $response['city']['name']; $validator = Validator::make($request->all(), ['town' => 'required|unique:towns,town']); if ($validator->fails()) { return redirect('')->withErrors($validator)->withInput(); } $town = new Town(); $town->town = $name; $town->id = $id; $town->save(); $this->update_weather($response['list'], $id); return redirect()->action('WeatherController@index'); }
/** * Search */ public function search(Request $request) { $properties = Property::orderBy('created_at', 'DESC'); if ($request->get('property_type') != 0) { $properties = $properties->where('property_type_id', $request->get('property_type')); } if ($request->get('property_status') != 0) { $properties = $properties->where('property_status_id', $request->get('property_status')); } if ($request->get('town_id') != 0) { $town = \App\Town::find($request->get('town_id')); $ids = []; foreach ($town->streets as $street) { $ids[] = $street->id; } $properties = $properties->whereIn('street_id', $ids); } elseif ($request->get('city_id') != 0) { $city = \App\City::find($request->get('city_id')); $ids = []; foreach ($city->towns->streets as $street) { $ids[] = $street->id; } $properties = $properties->whereIn('street_id', $ids); } if ($request->get("is_credit") != 0) { $properties = $properties->where('is_credit', $request->get('is_credit') == 1 ? true : false); } if ($request->get("is_site") != 0) { $properties = $properties->where('is_site', $request->get('is_site') == 1 ? true : false); } if ($request->get("min")) { $properties = $properties->where('price', '>=', $request->get('min')); } if ($request->get('max')) { $properties = $properties->where('price', '<=', $request->get('max')); } $properties = $properties->paginate(20); return view('property.index', ['properties' => $properties, "title" => trans('search.result')]); }
public function streets(StreetsRequest $request) { $town = Town::find($request->get("town_id")); $streets = $town->streets; return Response::json($streets); }
public static function towns($id) { return Town::where('state_id', '=', $id)->get(); }