phpvms/app/Http/Controllers/Api/FlightController.php

40 lines
999 B
PHP
Raw Normal View History

2017-08-15 07:26:20 +08:00
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Models\Airline;
use App\Models\Airport;
use App\Models\Flight;
use App\Models\Transformers\FlightTransformer;
use App\Http\Controllers\AppBaseController;
class FlightController extends AppBaseController
{
public function search(Request $request)
{
$where = [];
if($request->airline) {
$airline = Airline::where('code', $request->airline)->first()->id;
$where['airline_id'] = $airline;
}
if($request->depICAO) {
$airport = Airport::where('icao', $request->depICAO)->first()->id;
$where['dpt_airport_id'] = $airport;
}
if($request->arrICAO) {
$airport = Airport::where('icao', $request->depICAO)->first()->id;
$where['dpt_airport_id'] = $airport;
}
$flights = Flight::where($where)->get();
return fractal($flights, new FlightTransformer())->respond();
}
}