- How do I install nwidart/laravel-forecast in a Laravel application?
- Install it with Composer using composer require nwidart/laravel-forecast, then publish the package config file with php artisan vendor:publish and add your provider API key and default location. Laravel package discovery registers the service provider and facade automatically, so no manual wiring is required in a standard app. Once configured, you can resolve the service from the container or call the facade anywhere in your code.
- How do I get the current weather conditions with the Laravel Forecast facade?
- Call the facade, or inject the forecast service, and request current conditions for your configured default location or pass a location explicitly. The result comes back as a structured object, so you read named properties instead of parsing a raw HTTP payload. That makes it simple to render a dashboard widget or return JSON from a controller.
- Can I fetch a multi-day weather forecast, not just current conditions?
- Yes. The same service exposes upcoming forecasts, and the response is a collection of structured daily objects you can loop over. Use it to build a weekly table, a chart, or to schedule notifications based on upcoming weather. The maximum number of forecast days is limited by the upstream provider, so check its limits before promising a long range.
- Where do I put the API key and default location for Laravel Forecast?
- Publish the package config file and set your credentials, units, language, and default location there, ideally driven by environment variables so nothing sensitive ends up in version control. Remember that Laravel caches configuration in production, so re-run php artisan config:cache after changing values. If your secrets management injects environment variables at runtime, verify that the publish step does not encourage committing keys to the repository.
- Which PHP and Laravel versions does nwidart/laravel-forecast support?
- Check the package composer.json and README for the exact PHP and Laravel constraints, since version 2.x delegates the HTTP layer to nWidart/forecast-php and inherits that project's PHP floor and PSR/HTTP client requirements. Verify that matrix against your oldest supported runtime before adopting it, especially if you run services on older Laravel releases.
- How do I mock or fake the weather service when testing a Laravel app?
- Avoid hitting the live weather API in your test suite. Bind a stub implementation into the container or swap the facade root so it returns canned structured responses, then assert on your own formatting and business logic. That keeps tests fast and prevents failures caused by upstream outages, rate limits, or credential issues in CI.
- Can I override the configured defaults per request, and what takes precedence?
- The config file holds defaults for credentials, units, language, and location, while individual calls can still pass their own options. Confirm the documented precedence order for your installed version, which is typically call site over config over SDK default, and cover it with a test. This is exactly the boundary where a silent behavioural change can creep in after an upgrade.
- Does Laravel Forecast cache responses, and how should I handle rate limits in production?
- The package fits naturally into Laravel's caching layer, but the caching policy is yours to define. Wrap calls in Cache::remember with a TTL shorter than the forecast refresh interval to stay inside provider rate limits and keep response times low. Avoid caching current conditions for long periods if you display near real-time weather.
- What are the alternatives to nwidart/laravel-forecast for weather data in Laravel?
- If you need provider-agnostic abstractions or plan to switch weather providers, use nWidart/forecast-php directly or write a small adapter over the API you choose, since this package's value is Laravel ergonomics over that SDK. If you only need a single current-conditions call, Laravel's HTTP client and a few lines of your own code may be simpler than adding a dependency.
- Is upgrading nwidart/laravel-forecast safe, and how should I pin the version?
- Version 2.x moved the underlying client to nWidart/forecast-php, so response objects and exception types may now originate from the SDK rather than the package. Pin the major version and treat composer update for this package as a reviewed change, checking error paths and DTO shapes rather than only the happy path.