PHP code example of mhaggag / laravel-weather

1. Go to this page and download the library: Download mhaggag/laravel-weather 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/ */

    

mhaggag / laravel-weather example snippets


use MHaggag\LaravelWeather\Facades\Weather;

public function index()
{
    // Get current weather for Cairo (Lat: 30.0444, Lon: 31.2357)
    $current = Weather::current(30.0444, 31.2357);
    
    // With options (e.g., Arabic output)
    $currentAr = Weather::current(30.0444, 31.2357, ['locale' => 'ar']);
    
    return $current;
}

$rawData = Weather::get(30.0444, 31.2357, [
    'hourly' => ['temperature_2m', 'rain'],
    'daily' => ['temperature_2m_max']
]);

$data = Weather::format($rawData, [
    'units' => 'imperial',
    'locale' => 'en'
]);

$data = Weather::getAsFormatted(30.0444, 31.2357, [
    'units' => 'imperial',
    'locale' => 'en'
]);

$suggestion = Weather::getSuggestion($rawData, ['locale' => 'en']);
// Output: "Clear skies and high temperature — stay hydrated if heading out."

'suggestions' => [
    [
        'condition' => 'Rain',
        'message' => 'Don\'t forget your umbrella!',
    ],
    [
        'min_temp' => 35,
        'message' => 'It\'s scorching hot outside!',
    ],
],
bash
php artisan vendor:publish --provider="MHaggag\LaravelWeather\WeatherServiceProvider"

# Or publish specific resources:
php artisan vendor:publish --tag="weather-config"

php artisan vendor:publish --tag="weather-translations"

php artisan vendor:publish --tag="weather-views"