1. Go to this page and download the library: Download iaewing/laravel-opensky 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/ */
iaewing / laravel-opensky example snippets
use OpenSky\Laravel\Facades\OpenSky;
// Get all current state vectors
$states = OpenSky::getAllStateVectors();
// Get state vectors in a specific area (bounding box)
$states = OpenSky::getAllStateVectors(
lamin: 45.8389, // Switzerland
lomin: 5.9962,
lamax: 47.8229,
lomax: 10.5226
);
// Get flights in a time interval (max 1 hour)
$flights = OpenSky::getFlightsInTimeInterval(
begin: now()->subHour()->timestamp,
end: now()->timestamp
);
use OpenSky\Laravel\Client\OpenSkyClient;
class FlightController extends Controller
{
public function __construct(private OpenSkyClient $openSky)
{
}
public function index()
{
$states = $this->openSky->getAllStateVectors();
return view('flights.index', compact('states'));
}
}
// Get all state vectors (rate limited for anonymous users)
$states = OpenSky::getAllStateVectors(?int $time, ?array $icao24, ?float $lamin, ?float $lomin, ?float $lamax, ?float $lomax, ?int $extended);
// Get your own state vectors (
// Get flights in time interval (max 1 hour)
$flights = OpenSky::getFlightsInTimeInterval(int $begin, int $end);
// Get flights by aircraft (max 30 days)
$flights = OpenSky::getFlightsByAircraft(string $icao24, int $begin, int $end);
// Get arrivals by airport (max 7 days)
$flights = OpenSky::getArrivalsByAirport(string $airport, int $begin, int $end);
// Get departures by airport (max 7 days)
$flights = OpenSky::getDeparturesByAirport(string $airport, int $begin, int $end);
// Get track by aircraft
$track = OpenSky::getTrackByAircraft(string $icao24, int $time = 0);
$states = OpenSky::getAllStateVectors();
echo $states->time; // Unix timestamp
foreach ($states->states as $state) {
echo $state->icao24; // Aircraft identifier
echo $state->callsign; // Flight callsign
echo $state->originCountry; // Country of origin
echo $state->latitude; // Current latitude
echo $state->longitude; // Current longitude
echo $state->baroAltitude; // Barometric altitude
echo $state->velocity; // Ground speed
echo $state->onGround; // Is aircraft on ground
// ... and more properties
}
// Get all aircraft currently over Germany
$states = OpenSky::getAllStateVectors(
lamin: 47.3024,
lomin: 5.8662,
lamax: 55.0581,
lomax: 15.0419
);
foreach ($states->states as $aircraft) {
if (!$aircraft->onGround && $aircraft->velocity > 100) {
echo "Flight {$aircraft->callsign} at {$aircraft->baroAltitude}m altitude\n";
}
}
// Get all departures from Frankfurt Airport in the last hour
$flights = OpenSky::getDeparturesByAirport(
'EDDF',
now()->subHour()->timestamp,
now()->timestamp
);
$flightCount = $flights->flights->count();
echo "Frankfurt had {$flightCount} departures in the last hour\n";
// Track a specific aircraft's route
$track = OpenSky::getTrackByAircraft('3c4b26', now()->subHour()->timestamp);
$route = $track->path->map(function ($waypoint) {
return [
'lat' => $waypoint->latitude,
'lng' => $waypoint->longitude,
'alt' => $waypoint->baroAltitude,
'time' => date('H:i:s', $waypoint->time)
];
});
// Use $route for map visualization