Get weather data from Yr (MET Norway) in your Laravel apps. Simple, cached, and ready to use.
composer require ekstremedia/laravel-yrPublish the config:
php artisan vendor:publish --tag=yr-configAdd 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.
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=falseGET /api/weather/current?lat=59.9139&lon=10.7522GET /api/weather/current?address=Oslo,NorwayGET /api/weather/forecast?lat=59.9139&lon=10.7522GET /api/weather/sun?lat=59.9139&lon=10.7522GET /api/weather/moon?lat=59.9139&lon=10.7522{
"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"
}
}
}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);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=moonphaseWith the above config, routes become:
/weather/now(current weather)/weather/predictions(forecast)/weather/sunrise(sun data)/weather/moonphase(moon data)
use Ekstremedia\LaravelYr\Services\YrWeatherService;
$weather = app(YrWeatherService::class)->getCurrentWeather(59.9139, 10.7522);
return view('weather', ['weather' => $weather]);Current weather:
<x-yr-weather-card
:latitude="59.9139"
:longitude="10.7522"
location="Oslo, Norway"
/>5-Day Forecast:
<x-yr-forecast-card
:latitude="59.9139"
:longitude="10.7522"
location="Oslo"
:days="5"
/>Sunrise/Sunset:
<x-yr-sunrise-card
:latitude="59.9139"
:longitude="10.7522"
location="Oslo, Norway"
date="2025-12-25"
:offset="1"
/>Moon Phase:
<x-yr-moon-card
:latitude="59.9139"
:longitude="10.7522"
location="Oslo, Norway"
date="2025-12-25"
:offset="1"
/>const response = await fetch('/api/weather/current?address=Bergen,Norway');
const { data } = await response.json();
console.log(`${data.current.temperature}°C`);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
Sunrise/sunset responses include:
- Sunrise and sunset times with azimuth
- Solar noon and solar midnight
- Sun elevation angles
- Daylight duration (hours and minutes)
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
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.
The package intelligently caches all API requests:
- Weather data: Cached by coordinates and parameters. The cache automatically respects the
Expiresheader 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-Sinceheaders 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.
Want to change how the weather cards look? Publish the views:
php artisan vendor:publish --tag=yr-viewsThen 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-symbolsThis copies 83 weather symbol SVGs to public/vendor/laravel-yr/symbols.
All weather data is provided by The Norwegian Meteorological Institute (MET Norway) and is licensed under:
- Norwegian Licence for Open Government Data (NLOD) 2.0
- Creative Commons 4.0 BY International (CC 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.
The weather symbol SVG files are licensed under the MIT License. Copyright (c) 2015-2017 Yr.no.
This Laravel package code is licensed under the MIT License.
- Weather data: The Norwegian Meteorological Institute (MET Norway)
- Weather icons: Yr.no
- Package developed for easy integration of Norwegian weather data in Laravel applications
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.