PHPackages                             ekstremedia/laravel-yr - 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. ekstremedia/laravel-yr

ActiveLibrary[API Development](/categories/api)

ekstremedia/laravel-yr
======================

A lightweight Laravel package for integrating weather data from Yr (api.met.no)

v1.0.1(7mo ago)0670MITPHPPHP ^8.2CI passing

Since Nov 14Pushed 7mo agoCompare

[ Source](https://github.com/ekstremedia/laravel-yr)[ Packagist](https://packagist.org/packages/ekstremedia/laravel-yr)[ Docs](https://github.com/ekstremedia/laravel-yr)[ RSS](/packages/ekstremedia-laravel-yr/feed)WikiDiscussions main Synced today

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

Laravel Yr Weather
==================

[](#laravel-yr-weather)

Get weather data from [Yr (MET Norway)](https://api.met.no/) in your Laravel apps. Simple, cached, and ready to use.

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

[](#installation)

```
composer require ekstremedia/laravel-yr
```

Publish the config:

```
php artisan vendor:publish --tag=yr-config
```

Add your details to `.env`:

```
YR_USER_AGENT="YourApp/1.0 (your.email@example.com)"
```

> **Note:** MET Norway requires you to identify your app with contact info.

Quick Start
-----------

[](#quick-start)

### See it in action

[](#see-it-in-action)

Visit the interactive demo page:

```
http://yourapp.test/yr

```

The demo page features:

- **Live weather display** for any location
- **Location search** - Search by city name (e.g., "Oslo, Norway")
- **Manual coordinates** - Enter latitude/longitude directly
- **Real-time updates** - Weather components update as you change locations

**Search by location:**

```
http://yourapp.test/yr?location=Tokyo,Japan

```

**Use specific coordinates:**

```
http://yourapp.test/yr?latitude=59.9139&longitude=10.7522&location_name=Oslo

```

To disable the demo route, add to your `.env`:

```
YR_DEMO_ROUTE=false
```

### Get weather by coordinates

[](#get-weather-by-coordinates)

```
GET /api/weather/current?lat=59.9139&lon=10.7522
```

### Get weather by address

[](#get-weather-by-address)

```
GET /api/weather/current?address=Oslo,Norway
```

### Get forecast

[](#get-forecast)

```
GET /api/weather/forecast?lat=59.9139&lon=10.7522
```

### Get sunrise/sunset data

[](#get-sunrisesunset-data)

```
GET /api/weather/sun?lat=59.9139&lon=10.7522
```

### Get moon phase data

[](#get-moon-phase-data)

```
GET /api/weather/moon?lat=59.9139&lon=10.7522
```

Response Example
----------------

[](#response-example)

```
{
  "success": true,
  "data": {
    "current": {
      "temperature": 8.5,
      "feels_like": 6.2,
      "wind_speed": 3.2,
      "humidity": 65,
      "precipitation_amount": 0.0
    },
    "location": {
      "latitude": 59.9139,
      "longitude": 10.7522,
      "name": "Oslo, Norway"
    }
  }
}
```

Usage
-----

[](#usage)

### Using the Weather Helper (Recommended)

[](#using-the-weather-helper-recommended)

The easiest way to use this package is through the `WeatherHelper` service:

```
use Ekstremedia\LaravelYr\Services\WeatherHelper;

$helper = app(WeatherHelper::class);

// Get current weather by address
$result = $helper->getWeatherByAddress('Oslo, Norway');
// Returns: ['current' => [...], 'location' => [...]]

// Get current weather by coordinates
$result = $helper->getWeatherByCoordinates(59.9139, 10.7522, altitude: 90);

// Get forecast
$forecast = $helper->getForecastByAddress('Bergen, Norway');
$forecast = $helper->getForecastByCoordinates(60.39, 5.32, complete: true);

// Get sun data (sunrise/sunset)
$sun = $helper->getSunByAddress('Oslo, Norway');
$sun = $helper->getSunByCoordinates(59.9139, 10.7522, date: '2025-12-25', offset: 1);

// Get moon data (phase, rise/set)
$moon = $helper->getMoonByAddress('Bergen, Norway');
$moon = $helper->getMoonByCoordinates(60.39, 5.32, date: '2025-12-25', offset: 1);
```

### Using API Routes

[](#using-api-routes)

The package automatically registers API routes (fully configurable):

```
GET /api/weather/current?lat=59.9139&lon=10.7522
GET /api/weather/current?address=Oslo,Norway
GET /api/weather/forecast?lat=59.9139&lon=10.7522

```

**Customize API routes** in your `.env`:

```
# Disable API routes entirely
YR_API_ROUTES=false

# Customize route prefix (default: api/weather)
YR_API_ROUTE_PREFIX=weather

# Customize endpoint names
YR_API_CURRENT_ENDPOINT=now
YR_API_FORECAST_ENDPOINT=predictions
YR_API_SUN_ENDPOINT=sunrise
YR_API_MOON_ENDPOINT=moonphase
```

With the above config, routes become:

- `/weather/now` (current weather)
- `/weather/predictions` (forecast)
- `/weather/sunrise` (sun data)
- `/weather/moonphase` (moon data)

### Using Services Directly

[](#using-services-directly)

```
use Ekstremedia\LaravelYr\Services\YrWeatherService;

$weather = app(YrWeatherService::class)->getCurrentWeather(59.9139, 10.7522);

return view('weather', ['weather' => $weather]);
```

### In Blade templates

[](#in-blade-templates)

**Current weather:**

```

```

**5-Day Forecast:**

```

```

**Sunrise/Sunset:**

```

```

**Moon Phase:**

```

```

### In JavaScript

[](#in-javascript)

```
const response = await fetch('/api/weather/current?address=Bergen,Norway');
const { data } = await response.json();

console.log(`${data.current.temperature}°C`);
```

Available Data
--------------

[](#available-data)

### Weather Data

[](#weather-data)

Each weather response includes:

- Temperature (actual and feels-like)
- Wind (speed, direction, gusts)
- Humidity and pressure
- Cloud coverage
- Precipitation
- UV index
- Weather symbol/icon code

### Sun Data

[](#sun-data)

Sunrise/sunset responses include:

- Sunrise and sunset times with azimuth
- Solar noon and solar midnight
- Sun elevation angles
- Daylight duration (hours and minutes)

### Moon Data

[](#moon-data)

Moon phase responses include:

- Moon phase (degrees and name: New Moon, Waxing Crescent, etc.)
- Moon phase emoji visualization
- Moonrise and moonset times with azimuth
- High moon and low moon times with elevation

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

[](#configuration)

The config file (`config/yr.php`) has these settings:

```
return [
    // Required: User agent for MET Norway API
    'user_agent' => env('YR_USER_AGENT', 'YourApp/1.0 (contact@example.com)'),

    // Cache duration in seconds
    'cache_ttl' => env('YR_CACHE_TTL', 3600),

    // Enable/disable demo page at /yr
    'enable_demo_route' => env('YR_DEMO_ROUTE', true),

    // Enable/disable API routes
    'enable_api_routes' => env('YR_API_ROUTES', true),

    // Customize API route prefix (default: 'api/weather')
    'api_route_prefix' => env('YR_API_ROUTE_PREFIX', 'api/weather'),

    // Customize endpoint names
    'api_current_endpoint' => env('YR_API_CURRENT_ENDPOINT', 'current'),
    'api_forecast_endpoint' => env('YR_API_FORECAST_ENDPOINT', 'forecast'),
    'api_sun_endpoint' => env('YR_API_SUN_ENDPOINT', 'sun'),
    'api_moon_endpoint' => env('YR_API_MOON_ENDPOINT', 'moon'),
];
```

Weather data is automatically cached to avoid hitting the API too often.

### How caching works

[](#how-caching-works)

The package intelligently caches all API requests:

- **Weather data**: Cached by coordinates and parameters. The cache automatically respects the `Expires` header from MET Norway's API, typically updating every hour.
- **Geocoding**: Address lookups are cached for 7 days to minimize requests to the geocoding service.
- **Conditional requests**: The package uses `If-Modified-Since` headers to check if data has changed, reducing bandwidth usage.

All GET endpoints (`/api/weather/current` and `/api/weather/forecast`) benefit from this caching layer, ensuring fast responses while respecting API rate limits.

Customization
-------------

[](#customization)

Want to change how the weather cards look? Publish the views:

```
php artisan vendor:publish --tag=yr-views
```

Then edit `resources/views/vendor/laravel-yr/components/weather-card.blade.php`.

Want to use local weather icons? Publish the symbols:

```
php artisan vendor:publish --tag=yr-symbols
```

This copies 83 weather symbol SVGs to `public/vendor/laravel-yr/symbols`.

Licensing and Attribution
-------------------------

[](#licensing-and-attribution)

### Weather Data

[](#weather-data-1)

All weather data is provided by [The Norwegian Meteorological Institute (MET Norway)](https://www.met.no/) and is licensed under:

- [Norwegian Licence for Open Government Data (NLOD) 2.0](https://data.norge.no/nlod/en/2.0)
- [Creative Commons 4.0 BY International (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/)

When using this package, you must provide appropriate credit to MET Norway as the source of the weather data. The package components automatically include the required attribution.

**Required Attribution:**"Weather data from The Norwegian Meteorological Institute (MET Norway)"

For more details, see [MET Norway's Licensing and Crediting Policy](https://api.met.no/doc/License).

### Weather Icons

[](#weather-icons)

The weather symbol SVG files are licensed under the [MIT License](src/resources/symbols/LICENSE). Copyright (c) 2015-2017 Yr.no.

### Package Code

[](#package-code)

This Laravel package code is licensed under the MIT License.

Credits
-------

[](#credits)

- Weather data: [The Norwegian Meteorological Institute (MET Norway)](https://www.met.no/)
- Weather icons: [Yr.no](https://www.yr.no/)
- Package developed for easy integration of Norwegian weather data in Laravel applications

License
-------

[](#license)

MIT License - See LICENSE file for details

Note: This package's MIT license applies only to the package code itself. Weather data and icons have their own licenses as stated above.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance63

Regular maintenance activity

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

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

231d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/81c14fb7d455e136320a619693165f18eb4f220301b44512cdc083fa9b599bf7?d=identicon)[terjenesthus](/maintainers/terjenesthus)

---

Top Contributors

[![FdvTerje](https://avatars.githubusercontent.com/u/125031387?v=4)](https://github.com/FdvTerje "FdvTerje (1 commits)")

---

Tags

apiforecastlaravelmeteorologymoonmoon-phasespackagesunrisesunsetweatherweather-apiyryrnoyrno-weatherlaravelweatherforecastMET.nonorwayyr

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/ekstremedia-laravel-yr/health.svg)

```
[![Health](https://phpackages.com/badges/ekstremedia-laravel-yr/health.svg)](https://phpackages.com/packages/ekstremedia-laravel-yr)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)

PHPackages © 2026

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