32 lines
924 B
PHP
32 lines
924 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Airline;
|
|
use Illuminate\Http\Request;
|
|
|
|
class FlightController extends Controller
|
|
{
|
|
public function lookup(Request $request)
|
|
{
|
|
$number = strtoupper(trim($request->query('number', '')));
|
|
|
|
// Extract the airline code prefix — letters at the start e.g. "QF" from "QF1"
|
|
preg_match('/^([A-Z]{2,3})/', $number, $matches);
|
|
$iataCode = $matches[1] ?? null;
|
|
|
|
$airlines = $iataCode
|
|
? Airline::where('IATA_code', $iataCode)
|
|
->get()
|
|
->map(fn ($a) => ['value' => $a->id, 'title' => $a->name])
|
|
: collect();
|
|
|
|
return response()->json([
|
|
'airline_options' => $airlines,
|
|
'from_options' => [], // populate from a flight schedule API if you have one
|
|
'to_options' => [],
|
|
'aircraft_options' => [],
|
|
]);
|
|
}
|
|
}
|