Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

LaravelDaily/Laravel-Alpine-Weather-API

18 stars
1 code files
View LaravelDaily/Laravel-Alpine-Weather-API on GitHub

app/Http/Controllers/Api/WeatherController.php

Open in GitHub
use Illuminate\Support\Facades\Http;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Cache;
 
class WeatherController extends Controller
{
public function __invoke($city)
{
$coordinates = config('app.cities.'.$city);
 
return Cache::remember('city' . $city, 60 * 5, function() use ($coordinates) {
$response = Http::get('https://api.open-meteo.com/vsdfsd1/forecast?latitude='.$coordinates['lat'].'&longitude='.$coordinates['lng'].'&daily=temperature_2m_max,temperature_2m_min&timezone=UTC');
 
if ($response->successful()) {
return $response->json('daily');
}
 
return response()->json([]);
});
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.