PHP code example of royzhu / weather-horoscope-package

1. Go to this page and download the library: Download royzhu/weather-horoscope-package library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

royzhu / weather-horoscope-package example snippets


use RoyZhu\WeatherHoroscope\WeatherHoroscopePackage;

$package = new WeatherHoroscopePackage();

// 獲取歡迎訊息
echo $package->welcome('張三'); // 輸出: Hello, 張三! 歡迎使用 Weather Horoscope Package!

// 獲取當前時間
echo $package->getCurrentTime(); // 輸出: 2024-01-01 12:00:00

// 簡單計算
echo $package->add(5, 3); // 輸出: 8

// 獲取今日天氣資訊 (Array 格式)
$weather = $package->getDailyWeather();
// 返回: ['location' => '臺北市', 'weather_condition' => '多雲', 'temperature' => ['min' => '20', 'max' => '25'], ...]

// 獲取3小時降雨機率 (Array 格式)
$rainfall = $package->get3HourlyRainfallRate();
// 返回: ['location' => '信義區', 'forecasts' => [['time' => '09:00', 'probability' => 30], ...], ...]

// 獲取完整的天氣和星座報告 (Array 格式)
$report = $package->getWeatherAndHoroscopeReport();
// 返回: ['timestamp' => '2024-01-01 12:00:00', 'weather' => [...], 'rainfall' => [...], 'horoscope' => [...], ...]

// 格式化為字串 (如果需要)
echo $package->getFormattedReport();

// 獲取今日星座運勢 (Array 格式)
$horoscope = $package->getTodayHoroscope();
// 返回: ['date' => '2024-01-01', 'overall_luck' => ['top_stars' => ['牡羊座'], 'max_score' => 5], ...]

// 格式化為字串 (如果需要)
echo $package->formatHoroscopeAsString($horoscope);

// 在控制器或其他地方使用
$package = app('weather-horoscope');

// 獲取天氣資訊
$weather = $package->getDailyWeather();

// 獲取星座運勢
$horoscope = $package->getTodayHoroscope();

// 獲取完整報告
$report = $package->getWeatherAndHoroscopeReport();



namespace App\Http\Controllers;

use Illuminate\Http\Request;

class WeatherController extends Controller
{
    public function index()
    {
        $package = app('weather-horoscope');

        return response()->json([
            'weather' => $package->getDailyWeather(),
            'rainfall' => $package->get3HourlyRainfallRate(),
            'horoscope' => $package->getTodayHoroscope(),
            'full_report' => $package->getWeatherAndHoroscopeReport()
        ]);
    }
}
bash
php artisan vendor:publish --provider="RoyZhu\WeatherHoroscope\WeatherHoroscopeServiceProvider" --tag="config"