Fetch Weather Data in Laravel Projects

Fetch Weather Data in Laravel Projects

Laravel Weather by Henrik B Hansen allows you to fetch weather data from different weather providers in your Laravel projects. Here’s a quick example of what using this package looks like using the Facade:

// Weather response will always be a Collection of responses.
// Forecast days depends on the weather service provider.
$weather = weather()->getForecast($request);

// Current weather
$weather->first()->getCurrently();

You can customize the request when getting a forecast. Here’s an example from the readme:

use Vemcogroup\Weather\Providers\Provider;
use Vemcogroup\Weather\Request as WeatherRequest;
$request = new WeatherRequest('1 Infinite Loop, Cupertino, CA 95014, USA');
$request->withUnits(Provider::WEATHER_UNITS_FAHRENHEIT);

Out of the box, Laravel Weather supports Dark Sky and weatherstack; however, it looks like the Dark Sky API is deprecated or is not providing new keys. From the blog it reads:

Our API service for existing customers is not changing today, but we will no longer accept new signups. The API will continue to function through the end of 2021

You can define your own provider to work with this package using the provided abstract class.

You can learn more about this package, get full installation instructions, and view the source code on GitHub at vemcogroup/laravel-weather.

Filed in: News

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Full-Stack Engineer
[REMOTE: USA Only] All Other Applications Will be Rejected Immediately"
Curricula
Senior Full Stack PHP Developer
Canada
Motto Design Studio
Senior Software Engineer
Remote or Los Angeles
Coverfly
Sr. Software Engineer
Salt Lake City, UT
Clearlink
Senior Developer
Remote
ComplYant