manford / weatherman
:description
Requires
- guzzlehttp/guzzle: ^6.4
Requires (Dev)
- guzzlehttp/guzzle: ^6.4
This package is auto-updated.
Last update: 2024-09-20 18:13:15 UTC
README
A laravel wrapper for OpenWeather "city only" api
Installation
You can install this package via composer using this command:
$ composer require manford/weatherman
The Manford\Weatherman\WeathermanServiceProvider
is auto-discovered and registered by default.
If you want to register it yourself, add the ServiceProvider in config/app.php:
'providers' => [ /* * Package Service Providers... */ Manford\Weatherman\WeathermanServiceProvider::class, ]
The Weather
facade is also auto-discovered.
If you want to add it manually, add the Facade in config/app.php:
'aliases' => [ ... 'Weather' => Manford\Weatherman\Facades\Weatherman::class, ]
You can publish the config file with:
php artisan vendor:publish --provider="Manford\Weatherman\WeathermanServiceProvider"
This is the contents of the published config file located in config/weatherman.php
.
return [ 'base_url' => env('OPEN_WEATHER_URL'), 'app_id' => env('OPEN_WEATHER_ID') ];
Add and update your .env file with these.
Visit OpenWeather to get your ID.
OPEN_WEATHER_URL=https://api.openweathermap.org/data/2.5/weather
OPEN_WEATHER_ID=
Usage
In your controller:
namespace App\Http\Controllers; use Illuminate\Http\Request; use Manford\Weatherman\Facades\Weatherman as Weather; class PageController extends Controller { public function index() { $city = Weather::city('accra'); return view('welcome', compact('city')); } }
Include this view where you need it:
<div class="card-body"> <h2>{{ $city->name }} Weather Status</h2> <div class="time"> <div>{{ date("l g:i a", time()) }}</div> <div>{{ date("jS F, Y", time()) }}</div> <div>{{ ucwords($city->weather[0]->description) }}</div> </div> <div class="weather-forecast"> <img src="http://openweathermap.org/img/w/{{ $city->weather[0]->icon }}.png" class="weather-icon" /> <?php echo $city->main->temp_max; ?>°C <span class="min-temperature"> {{ $city->main->temp_min }}°C </span> </div> <div class="time"> <div>Humidity: {{ $city->main->humidity }} %</div> <div>Wind: {{ $city->wind->speed }} km/h</div> </div> </div>
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email benjaminmanford@gmail.com instead of using the issue tracker.
Credits
License
MIT. Please see the license file for more information.