2018-03-28 00:40:37 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Frontend;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Controller;
|
2018-03-28 00:40:37 +08:00
|
|
|
use App\Repositories\AirportRepository;
|
|
|
|
use App\Repositories\FlightRepository;
|
|
|
|
use Flash;
|
|
|
|
use Request;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class HomeController
|
|
|
|
*/
|
|
|
|
class AirportController extends Controller
|
|
|
|
{
|
2018-08-27 00:40:04 +08:00
|
|
|
private $airportRepo;
|
|
|
|
private $flightRepo;
|
2018-03-28 00:40:37 +08:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
AirportRepository $airportRepo,
|
|
|
|
FlightRepository $flightRepo
|
|
|
|
) {
|
|
|
|
$this->airportRepo = $airportRepo;
|
|
|
|
$this->flightRepo = $flightRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the airport
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @param mixed $id
|
2018-08-27 02:50:08 +08:00
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
2018-03-28 00:40:37 +08:00
|
|
|
*/
|
|
|
|
public function show($id, Request $request)
|
|
|
|
{
|
|
|
|
$id = strtoupper($id);
|
|
|
|
|
2021-05-09 03:42:18 +08:00
|
|
|
$airport = $this->airportRepo->where('id', $id)->first();
|
|
|
|
if (!$airport) {
|
2018-03-28 00:40:37 +08:00
|
|
|
Flash::error('Airport not found!');
|
|
|
|
return redirect(route('frontend.dashboard.index'));
|
|
|
|
}
|
|
|
|
|
2018-08-26 21:43:47 +08:00
|
|
|
$inbound_flights = $this->flightRepo
|
|
|
|
->with(['dpt_airport', 'arr_airport', 'airline'])
|
|
|
|
->findWhere([
|
|
|
|
'arr_airport_id' => $id,
|
2021-05-09 03:42:18 +08:00
|
|
|
'active' => 1,
|
2018-08-26 21:43:47 +08:00
|
|
|
])->all();
|
|
|
|
|
|
|
|
$outbound_flights = $this->flightRepo
|
|
|
|
->with(['dpt_airport', 'arr_airport', 'airline'])
|
|
|
|
->findWhere([
|
|
|
|
'dpt_airport_id' => $id,
|
2021-05-09 03:42:18 +08:00
|
|
|
'active' => 1,
|
2018-08-26 21:43:47 +08:00
|
|
|
])->all();
|
2018-03-28 00:40:37 +08:00
|
|
|
|
|
|
|
return view('airports.show', [
|
2018-08-27 00:40:04 +08:00
|
|
|
'airport' => $airport,
|
|
|
|
'inbound_flights' => $inbound_flights,
|
2018-03-28 00:40:37 +08:00
|
|
|
'outbound_flights' => $outbound_flights,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|