38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Airport;
|
|
use Illuminate\Console\Attributes\Description;
|
|
use Illuminate\Console\Attributes\Signature;
|
|
use Illuminate\Console\Command;
|
|
|
|
#[Signature('app:populate-airport-timezones')]
|
|
#[Description('Command description')]
|
|
class PopulateAirportTimezones extends Command
|
|
{
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle()
|
|
{
|
|
Airport::whereNull('timezone')->chunk(100, function ($airports) {
|
|
foreach ($airports as $airport) {
|
|
$response = Http::get('http://api.timezonedb.com/v2.1/get-timezone', [
|
|
'key' => config('app.timezone_db_key'),
|
|
'format' => 'json',
|
|
'by' => 'position',
|
|
'lat' => $airport->latitude,
|
|
'lng' => $airport->longitude,
|
|
]);
|
|
|
|
if ($response->ok()) {
|
|
$airport->update(['timezone' => $response->json('zoneName')]);
|
|
}
|
|
|
|
sleep(1);
|
|
}
|
|
});
|
|
}
|
|
}
|