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' => [], ]); } }