Added Charts
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?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' => [],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user