2017-06-12 00:36:16 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
2018-01-05 11:07:23 +08:00
|
|
|
use Log;
|
|
|
|
use Flash;
|
2017-06-12 00:36:16 +08:00
|
|
|
use App\Http\Requests\CreateAirportRequest;
|
|
|
|
use App\Http\Requests\UpdateAirportRequest;
|
|
|
|
use App\Repositories\AirportRepository;
|
2018-01-04 10:07:34 +08:00
|
|
|
use App\Repositories\Criteria\WhereCriteria;
|
2017-06-12 00:36:16 +08:00
|
|
|
use Illuminate\Http\Request;
|
2017-12-07 06:07:25 +08:00
|
|
|
use Jackiedo\Timezonelist\Facades\Timezonelist;
|
2017-06-12 00:36:16 +08:00
|
|
|
use Response;
|
|
|
|
|
2017-08-14 11:22:14 +08:00
|
|
|
|
|
|
|
class AirportController extends BaseController
|
2017-06-12 00:36:16 +08:00
|
|
|
{
|
|
|
|
/** @var AirportRepository */
|
|
|
|
private $airportRepository;
|
|
|
|
|
|
|
|
public function __construct(AirportRepository $airportRepo)
|
|
|
|
{
|
|
|
|
$this->airportRepository = $airportRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the Airport.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @return Response
|
2017-12-08 07:22:15 +08:00
|
|
|
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
2017-06-12 00:36:16 +08:00
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
2018-01-04 10:07:34 +08:00
|
|
|
$where = [];
|
|
|
|
if($request->has('icao')) {
|
|
|
|
$where['icao'] = $request->get('icao');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->airportRepository->pushCriteria(new WhereCriteria($request, $where));
|
2018-01-04 10:03:39 +08:00
|
|
|
$airports = $this->airportRepository->orderBy('icao', 'asc')->paginate(40);
|
2017-06-12 00:36:16 +08:00
|
|
|
|
2017-07-06 07:48:32 +08:00
|
|
|
return view('admin.airports.index', [
|
|
|
|
'airports' => $airports,
|
|
|
|
]);
|
2017-06-12 00:36:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new Airport.
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2017-12-08 07:22:15 +08:00
|
|
|
return view('admin.airports.create', [
|
|
|
|
'timezones' => Timezonelist::toArray(),
|
|
|
|
]);
|
2017-06-12 00:36:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created Airport in storage.
|
|
|
|
* @param CreateAirportRequest $request
|
|
|
|
* @return Response
|
2017-12-08 07:22:15 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2017-06-12 00:36:16 +08:00
|
|
|
*/
|
|
|
|
public function store(CreateAirportRequest $request)
|
|
|
|
{
|
|
|
|
$input = $request->all();
|
2018-01-22 02:43:32 +08:00
|
|
|
$input['hub'] = get_truth_state($input['hub']);
|
2018-01-05 11:07:23 +08:00
|
|
|
|
2018-01-05 13:31:57 +08:00
|
|
|
$this->airportRepository->create($input);
|
2017-06-12 00:36:16 +08:00
|
|
|
|
|
|
|
Flash::success('Airport saved successfully.');
|
|
|
|
return redirect(route('admin.airports.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified Airport.
|
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
|
|
|
$airport = $this->airportRepository->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($airport)) {
|
|
|
|
Flash::error('Airport not found');
|
|
|
|
return redirect(route('admin.airports.index'));
|
|
|
|
}
|
|
|
|
|
2017-07-06 07:48:32 +08:00
|
|
|
return view('admin.airports.show', [
|
|
|
|
'airport' => $airport,
|
|
|
|
]);
|
2017-06-12 00:36:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified Airport.
|
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
$airport = $this->airportRepository->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($airport)) {
|
|
|
|
Flash::error('Airport not found');
|
|
|
|
return redirect(route('admin.airports.index'));
|
|
|
|
}
|
|
|
|
|
2017-07-06 07:48:32 +08:00
|
|
|
return view('admin.airports.edit', [
|
2017-12-07 06:07:25 +08:00
|
|
|
'timezones' => Timezonelist::toArray(),
|
2017-07-06 07:48:32 +08:00
|
|
|
'airport' => $airport,
|
|
|
|
]);
|
2017-06-12 00:36:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified Airport in storage.
|
2017-12-08 07:22:15 +08:00
|
|
|
* @param int $id
|
2017-06-12 00:36:16 +08:00
|
|
|
* @param UpdateAirportRequest $request
|
|
|
|
* @return Response
|
2017-12-08 07:22:15 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2017-06-12 00:36:16 +08:00
|
|
|
*/
|
|
|
|
public function update($id, UpdateAirportRequest $request)
|
|
|
|
{
|
|
|
|
$airport = $this->airportRepository->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($airport)) {
|
|
|
|
Flash::error('Airport not found');
|
|
|
|
return redirect(route('admin.airports.index'));
|
|
|
|
}
|
|
|
|
|
2018-01-05 11:07:23 +08:00
|
|
|
$attrs = $request->all();
|
2018-01-22 02:43:32 +08:00
|
|
|
$attrs['hub'] = get_truth_state($attrs['hub']);
|
2018-01-05 13:22:31 +08:00
|
|
|
|
2018-01-05 13:31:57 +08:00
|
|
|
$this->airportRepository->update($attrs, $id);
|
2017-06-12 00:36:16 +08:00
|
|
|
|
|
|
|
Flash::success('Airport updated successfully.');
|
|
|
|
return redirect(route('admin.airports.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified Airport from storage.
|
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
$airport = $this->airportRepository->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($airport)) {
|
|
|
|
Flash::error('Airport not found');
|
|
|
|
return redirect(route('admin.airports.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->airportRepository->delete($id);
|
|
|
|
|
|
|
|
Flash::success('Airport deleted successfully.');
|
|
|
|
return redirect(route('admin.airports.index'));
|
|
|
|
}
|
2017-07-06 07:48:32 +08:00
|
|
|
|
|
|
|
public function fuel(Request $request)
|
|
|
|
{
|
|
|
|
$id = $request->id;
|
|
|
|
|
|
|
|
$airport = $this->airportRepository->findWithoutFail($id);
|
|
|
|
if (empty($airport)) {
|
|
|
|
Flash::error('Flight not found');
|
|
|
|
return redirect(route('admin.flights.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// add aircraft to flight
|
|
|
|
if ($request->isMethod('put')) {
|
|
|
|
$airport->{$request->name} = $request->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
$airport->save();
|
|
|
|
}
|
2017-06-12 00:36:16 +08:00
|
|
|
}
|