Package Data | |
---|---|
Maintainer Username: | nWidart |
Maintainer Contact: | n.widart@gmail.com (Nicolas Widart) |
Package Create Date: | 2014-08-03 |
Package Last Update: | 2015-08-02 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 03:00:16 |
Package Statistics | |
---|---|
Total Downloads: | 4,917 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 2 |
Total Forks: | 6 |
Total Open Issues: | 3 |
Laravel 5 compatible package
| Laravel version | Package version | | ---------------- | --------------- | | ~4.2 | ~1.2 | | ~5.1 | ~2.1 |
Laravel-forecast provides a service provider and a facade around the Forecast-php wrapper.
Want to use this as a standalone package ? Checkout the Forecast-php API wrapper.
$ composer require nwidart/laravel-forecast
Add the service provider in app/config/app.php
'providers' => [
...
Nwidart\LaravelForecast\LaravelForecastServiceProvider::class
]
Add the Alias provider in app/config/app.php
'aliases' => [
...
'Forecast' => Nwidart\LaravelForecast\ForecastFacade::class,
]
Publish the configuration file and add your forecast API key
$ php artisan vendor:publish --provider="Nwidart\LaravelForecast\LaravelForecastServiceProvider"
<?php
Forecast::get('37.8267','-122.423');
// Get the forecast at a given time
Forecast::get(('37.8267','-122.423', '2013-05-06T12:00:00-0400')
In the settings you can add global options that will have used on every request made to Forecast.io. You can add this in the options
key of the settings file.
For instance if you want temperature in Celsius:
'options' => [
'units' => 'si',
],
For more details and all available options check the official documentation.
You can also inject the Nwidart\ForecastPhp\Forecast
class into your constructor.
/**
* @var \Nwidart\ForecastPhp\Forecast
*/
private $forecast;
public function __construct(\Nwidart\ForecastPhp\Forecast $forecast)
{
$this->forecast = $forecast;
}
public function doSomething()
{
$weather = $this->forecast->get($lat, $lon);
}