PHPackages                             rawaby88/open-weather-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. rawaby88/open-weather-laravel

ActiveLibrary[API Development](/categories/api)

rawaby88/open-weather-laravel
=============================

Laravel package to provide Open Weather Map API integration

1.0.1(5y ago)138MITPHP

Since Mar 13Pushed 5y ago1 watchersCompare

[ Source](https://github.com/rawaby88/open-weather-laravel)[ Packagist](https://packagist.org/packages/rawaby88/open-weather-laravel)[ RSS](/packages/rawaby88-open-weather-laravel/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Open Weather Map Laravel
========================

[](#open-weather-map-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bd5a2386fe5a6d977835e34d666aa92f2200768841d5a333c84c7f1f1e386894/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72617761627938382f6f70656e2d776561746865722d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rawaby88/open-weather-laravel)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3565811743af98ff6a7b69be0067afef917f07ce11643b56b862af6ab874a452/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f72617761627938382f6f70656e2d776561746865722d6c61726176656c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/rawaby88/open-weather-laravel/?branch=main)[![Build Status](https://camo.githubusercontent.com/19e71fe28a808aa85b62db3862bb044f8609b26e33a15ada3546b257a7aa5e65/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f72617761627938382f6f70656e2d776561746865722d6c61726176656c2f6261646765732f6275696c642e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/rawaby88/open-weather-laravel/build-status/main)[![Code Intelligence Status](https://camo.githubusercontent.com/b35c2ff7347213dd7d0b2bc30ce1dee542833cc4c86fc18ac1405c30e4ccc325/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f72617761627938382f6f70656e2d776561746865722d6c61726176656c2f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d61696e)](https://scrutinizer-ci.com/code-intelligence)[![GitHub license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE.md)

🌡 Laravel package to provide Open Weather map API integration.

#### [Star ⭐](https://github.com/rawaby88/open-weather-laravel) repo to show suport 🍺

[](#star--repo-to-show-suport-)

To use this package you'll need to register into Open Weather Map service and generate an API Key. For more information visit: [https://home.openweathermap.org/api\_keys](https://home.openweathermap.org/api_keys)

Installation
------------

[](#installation)

Require this package with composer:

```
composer require rawaby88/open-weather-laravel
```

### Add Service Provider &amp; Facade

[](#add-service-provider--facade)

#### For Laravel 5.5+

[](#for-laravel-55)

Once the package is added, the service provider and facade will be autodiscovered.

#### For Older versions of Laravel

[](#for-older-versions-of-laravel)

Add the ServiceProvider to the providers array in `config/app.php`:

```
Rawaby88\OpenWeatherMap\Providers\OpenWeatherServiceProvider::class,

```

### Publish Config

[](#publish-config)

Once done, publish the config to your config folder using:

```
php artisan vendor:publish --provider="Rawaby88\OpenWeatherMap\Providers\OpenWeatherServiceProvider"

```

Configuration
-------------

[](#configuration)

Once the config file is published, open `config/open-weather.php`

#### Global config

[](#global-config)

`api_token`
Your API key goes here. Or add it to your .env file `WEATHER_API_TOKEN`

`api_icon_url`
Url display the icons that sent from the API / or create your own icons

`unit`
Temperature is available in fahrenheit, celsius and kelvin units.

`language`
Weather description language.

Usage
-----

[](#usage)

### Call current weather data for one location

[](#call-current-weather-data-for-one-location)

#### By city name

[](#by-city-name)

You can call by city name or city name and country code or city name, country state code . Please note that searching by states available only for the USA locations.

```
use Rawaby88\OpenWeatherMap\Services\CWByCityName;

$cw = (new CWByCityName('London'))->get();
/**
 * With ISO 3166 country codes
 * $cw = (new CWByCityName('Warsaw', 'pl'))->get();
 */
```

#### By city id

[](#by-city-id)

You can make an API call by city ID. List of city ID 'city.list.json.gz' can be downloaded

- here

```
use Rawaby88\OpenWeatherMap\Services\CWByCityId;

$cw = (new CWByCityId(2172797))->get();
```

#### By geographic coordinates

[](#by-geographic-coordinates)

You can make an API call by zip code. Please note if country is not specified then the search works for USA as a default.

```
use Rawaby88\OpenWeatherMap\Services\CWByZipCode;

$cw = (new CWByZipCode(94040, 'us'))->get();
```

#### By ZIP code

[](#by-zip-code)

You can call by latitude and longitude coordinates

```
use Rawaby88\OpenWeatherMap\Services\CWByCoordinates;

// CWByCoordinates(latitude, longitude)
$cw = (new CWByCoordinates(35, 139))->get();
```

#### Example for single result

[](#example-for-single-result)

```
use Rawaby88\OpenWeatherMap\Services\CWByCityName;

$cw = (new CWByCityName('London'))->get();
/**
 * With ISO 3166 country codes
 * $cw = (new CWByCityName('Warsaw', 'pl'))->get();
 */

$temperature = $cw->temperature; // return Temperature object
$weather     = $cw->weather;     // return Weather object
$location    = $cw->location;    // return Location object
$sun         = $cw->sun;         // return Sun object

/**
 * Each one of [temperature, weather, location, sun]
 * can be encoded to json by calling toJson();
 */
$temperature->toJson();
$weather->toJson();
$location->toJson();
$sun->toJson();
```

### Call current weather data for several cities

[](#call-current-weather-data-for-several-cities)

#### Cities within a rectangle zone

[](#cities-within-a-rectangle-zone)

API returns the data from cities within the defined rectangle specified by the geographic coordinates.

```
use Rawaby88\OpenWeatherMap\Services\CWByRectangleZone;

//CWByRectangleZone(lon-left,lat-bottom,lon-right,lat-top,zoom)
$cw = (new CWByRectangleZone(12,32,15,37,10))->get();
```

#### Cities within a rectangle zone

[](#cities-within-a-rectangle-zone-1)

API returns the data from cities within the defined rectangle specified by the geographic coordinates.

```
use Rawaby88\OpenWeatherMap\Services\CWByCitiesInCircle;

//CWByCitiesInCircle(latitude, longitude, number_of cities_to_return)
$cw = (new CWByCitiesInCircle(55.5, 37.5, 10))->get();
```

#### Example for several cities

[](#example-for-several-cities)

```
use Rawaby88\OpenWeatherMap\Services\CWByCitiesInCircle;

$cw = (new CWByCitiesInCircle(55.5, 37.5, 10))->get();

//to loop through cities result
foreach ($cw->list as $city)
{
    $temperature = $city->temperature; // return Temperature object
    $weather     = $city->weather;     // return Weather object
    $location    = $city->location;    // return Location object
    $sun         = $city->sun;         // return Sun object
}

//get specific city with index
$city1 = $cw->index(2);

//get cities count in the list
$city1 = $cw->count();

//get the first city in the list
$city1 = $cw->first();
```

#### Temperature Object

[](#temperature-object)

Contents Temperature information

```
use Rawaby88\OpenWeatherMap\Services\CWByCityName;

$cw = (new CWByCityName('London'))->get();
$temperature = $cw->temperature;

$temperature->temp; //return current temperature
$temperature->feelsLike; //return feels like
$temperature->tempMax; //return max temperature
$temperature->tempMin; //return min temperature
$temperature->pressure; //return pressure
$temperature->humidity; //return humidity

/**
 * toJson()
 * {"temp":9,"feelsLike":4,"tempMax":10,"tempMin":9,"pressure":1000,"humidity":53}
 */
$temperature->toJson();
```

#### Weather Object

[](#weather-object)

Contents Weather information

```
use Rawaby88\OpenWeatherMap\Services\CWByCityName;

$cw = (new CWByCityName('London'))->get();
$weather = $cw->weather;

$weather->condition; //return current condition
$weather->description; //return weather description
$weather->icon; //return weather icon
$weather->iconUrl; //return icon url
$weather->windSpeed; //return wind speed
$weather->windDeg; //return wind degree
$weather->windDir; //return wind direction
$weather->clouds; //return clouds
$weather->precipitationVolume; //return rain volume
$weather->snowVolume; //return snow volume

/**
 * toJson()
 * {"condition":"Clouds","description":"broken clouds","icon":"04d","iconUrl":"\/\/openweathermap.org\/img\/w\/04d.png","windSpeed":5.14,"windDeg":210,"windDir":"SSW","clouds":75,"precipitationVolume":[],"snowVolume":[]}
 */
$weather->toJson();
```

#### Sun Object

[](#sun-object)

Contents Sun information

```
use Rawaby88\OpenWeatherMap\Services\CWByCityName;

$cw = (new CWByCityName('London'))->get();
$sun = $cw->sun;

$sun->sunrise; //return sunrise
$sun->sunset; //return sunset
$sun->timezone; //return timezone

/**
 * toJson()
 * {"sunrise":{"date":"2021-03-13 05:54:53.000000","timezone_type":1,"timezone":"+00:00"},"sunset":{"date":"2021-03-13 17:36:07.000000","timezone_type":1,"timezone":"+00:00"},"timezone":3600}
 */
$sun->toJson();
```

#### Location Object

[](#location-object)

Contents Location information

```
use Rawaby88\OpenWeatherMap\Services\CWByCityName;

$cw = (new CWByCityName('London'))->get();
$location = $cw->location;

$location->city; //return city name
$location->countryCode; //return ISO country code
$location->lon; //return longitude coordinate
$location->lat; //return latitude coordinate

/**
 * toJson()
 * {"city":"Warsaw","countryCode":"PL","lon":21.0118,"lat":52.2298}
 */
$location->toJson();
```

### Parameters unit &amp; language

[](#parameters-unit--language)

Weather parameters unit

```
use Rawaby88\OpenWeatherMap\Services\CWByCityName;

$cw = new CWByCityName('London');

/**
 * You can change the unit type before making the call.
 * The default value will be called from config file if there was no changes.
 */
$cw->setUnitType('imperial');

/**
 * You can also change the language before making the call
 * The default value will be called from config file if there was no changes.
 */
$cw->setLanguage('pl');

$cw->volUnit; // rain and snow volume unit | mm
$cw->presUnit; // pressure unit | hPa
$cw->distUnit; //Distance unit meter/sec | miles/hour
$cw->tempUnit; //Temperature unit Kelvin | Celsius | Fahrenheit.

$cw->get();
```

Contributing
------------

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Mahmoud Osman](https://github.com/rawaby88)
- [All Contributors](../../contributors)

License
-------

[](#license)

[MIT](./LICENSE.md)The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1886d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5a26344976d8ebbaa7896e254939250e43e600e0cbecc4b4762d5dede0bbb13b?d=identicon)[rawaby88](/maintainers/rawaby88)

---

Top Contributors

[![rawaby88](https://avatars.githubusercontent.com/u/3300771?v=4)](https://github.com/rawaby88 "rawaby88 (13 commits)")

---

Tags

apilaravelweather

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rawaby88-open-weather-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/rawaby88-open-weather-laravel/health.svg)](https://phpackages.com/packages/rawaby88-open-weather-laravel)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
