ecce/laravel-weather

Laravel 天气包

dev-main 2023-09-24 10:21 UTC

This package is auto-updated.

Last update: 2024-09-24 12:32:43 UTC


README

“Laravel 天气包”是一个强大的工具,可以将天气预报数据集成到您的 Laravel 应用程序中。它允许您获取指定 IP 地址的天气数据,显示地理定位信息,并展示带有可视化地图的5天天气预报。

安装

要开始使用 Laravel 天气包,请按照以下步骤操作:

  1. 配置 composer.json
"minimum-stability": "dev",
  1. 通过 Composer 安装包
composer require ecce/laravel-weather
  1. 发布包配置和视图
php artisan vendor:publish --tag=laravel-weather-config
php artisan vendor:publish --tag=laravel-weather-assets
php artisan vendor:publish --tag=laravel-weather-views
  1. 在 config/laravel-weather.php 文件中配置您的 API 密钥。请访问 - https://openweathermap.org/api
return [
    'api_key' => env('OPEN_WEATHER_API_KEY', ''),
];
  1. 获取数据选项
use Ecce\LaravelWeather\Facades\LaravelWeather;

// Example: Fetch weather data for an IP address
$ipAddress = '123.45.67.89';
$weatherData = LaravelWeather::getDailyForecast($ipAddress);
$geoLocation = $weatherData['geoLocation'];
$forecast = $weatherData['forecast'];
  1. 访问 Laravel 应用程序中的 URL,访问 /weather-forecasts