PHP code example of rakibdevs / openweather-laravel-api

1. Go to this page and download the library: Download rakibdevs/openweather-laravel-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rakibdevs / openweather-laravel-api example snippets


'providers' => [
    // ...
    RakibDevs\Weather\WeatherServiceProvider::class,
],
'aliases' => [
    //...
    'Weather' => RakibDevs\Weather\Weather::class,	
];



	return [
	    'api_key' 	        => env('OPENWEATHER_API_KEY', ''),
    	    'onecall_api_version' => '2.5',
            'historical_api_version' => '2.5',
            'forecast_api_version' => '2.5',
            'pollution_api_version' => '2.5',   // legacy misspelled 'polution_api_version' is still honored
            'geo_api_version' => '1.0',
	    'lang' 		=> env('OPENWEATHER_API_LANG', 'en'),
	    'date_format'       => 'm/d/Y',
	    'time_format'       => 'h:i A',
	    'day_format'        => 'l',
	    'temp_format'       => 'c',        // c for celcius, f for farenheit, k for kelvin
	    'cache_enabled'     => env('OPENWEATHER_CACHE_ENABLED', false),
	    'cache_ttl'         => env('OPENWEATHER_CACHE_TTL', 600),  // seconds
	];

use RakibDevs\Weather\Weather;

$wt = new Weather();

$info = $wt->getCurrentByCity('dhaka');    // Get current weather by city name



use RakibDevs\Weather\Facades\Weather;

$info = Weather::getCurrentByCity('dhaka');

$info = app('weather')->getCurrentByCity('dhaka');

// c = metric, f = imperial, k = standard
$info = $wt->units('f')->lang('bn')->getCurrentByCity('dhaka');

$res = $wt->fluent()->getCurrentByCity('dhaka');

// backward-compatible property access still works
$res->main->temp;

// dot-notation access with default
$res->get('main.temp');
$res->get('weather.0.description', 'n/a');
$res->has('wind.gust');

// convenience getters (current-weather shape)
$res->temperature();     // main.temp
$res->feelsLike();       // main.feels_like
$res->humidity();        // main.humidity
$res->windSpeed();       // wind.speed
$res->condition();       // weather.0.main
$res->description();     // weather.0.description
$res->city();            // name
$res->country();         // sys.country
$res->icon();            // weather.0.icon
$res->iconUrl();         // https://openweathermap.org/img/wn/[email protected]

// conversions & collections
$res->toArray();
$res->toJson();
$res->raw();                       // the original stdClass, untouched
$res->collect('list');             // Illuminate\Support\Collection (for list responses)

// ArrayAccess (dot notation supported)
$res['main.temp'];


// By city name
$info = $wt->getCurrentByCity('dhaka'); 

// By city ID - download list of city id here http://bulk.openweathermap.org/sample/
$info = $wt->getCurrentByCity(1185241); 

// By Zip Code - string with country code 
$info = $wt->getCurrentByZip('94040,us');  // If no country code specified, us will be default

// By coordinates : latitude and longitude
$info = $wt->getCurrentByCord(23.7104, 90.4074);


// By coordinates : latitude and longitude
$info = $wt->getOneCallByCord(23.7104, 90.4074);


// By city name
$info = $wt->get3HourlyByCity('dhaka'); 

// By city ID - download list of city id here http://bulk.openweathermap.org/sample/
$info = $wt->get3HourlyByCity(1185241); 

// By Zip Code - string with country code 
$info = $wt->get3HourlyByZip('94040,us');  // If no country code specified, us will be default

// By coordinates : latitude and longitude
$info = $wt->get3HourlyByCord(23.7104, 90.4074);



// By coordinates : latitude, longitude and date
$info = $wt->getHistoryByCord(23.7104, 90.4074, '2020-01-09');



// By coordinates : latitude, longitude and date
$info = $wt->getAirPollutionByCord(23.7104, 90.4074);


// By city name
$info = $wt->getGeoByCity('dhaka');

// By coordinates : latitude, longitude and date
$info = $wt->getGeoByCity(23.7104, 90.4074);


	$ php artisan vendor:publish