From f4e7eef40c89c9e7b3505afc4c67690cfc072467 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Sat, 17 Jun 2017 17:25:36 -0500 Subject: [PATCH] #14 initial scaffolding for adding flights/schedules --- .../Controllers/Admin/FlightController.php | 178 ++++++++++++++++++ app/Http/Requests/CreateFlightRequest.php | 30 +++ app/Http/Requests/UpdateFlightRequest.php | 30 +++ app/Models/Flight.php | 85 +++++++++ app/Repositories/FlightRepository.php | 25 +++ ...2017_06_17_214650_create_flights_table.php | 52 +++++ .../views/admin/flights/create.blade.php | 22 +++ resources/views/admin/flights/edit.blade.php | 21 +++ .../views/admin/flights/fields.blade.php | 77 ++++++++ resources/views/admin/flights/index.blade.php | 23 +++ resources/views/admin/flights/show.blade.php | 17 ++ .../views/admin/flights/show_fields.blade.php | 90 +++++++++ resources/views/admin/flights/table.blade.php | 41 ++++ resources/views/admin/menu.blade.php | 1 + routes/web.php | 5 + 15 files changed, 697 insertions(+) create mode 100644 app/Http/Controllers/Admin/FlightController.php create mode 100644 app/Http/Requests/CreateFlightRequest.php create mode 100644 app/Http/Requests/UpdateFlightRequest.php create mode 100644 app/Models/Flight.php create mode 100644 app/Repositories/FlightRepository.php create mode 100644 database/migrations/2017_06_17_214650_create_flights_table.php create mode 100644 resources/views/admin/flights/create.blade.php create mode 100644 resources/views/admin/flights/edit.blade.php create mode 100644 resources/views/admin/flights/fields.blade.php create mode 100644 resources/views/admin/flights/index.blade.php create mode 100644 resources/views/admin/flights/show.blade.php create mode 100644 resources/views/admin/flights/show_fields.blade.php create mode 100644 resources/views/admin/flights/table.blade.php diff --git a/app/Http/Controllers/Admin/FlightController.php b/app/Http/Controllers/Admin/FlightController.php new file mode 100644 index 00000000..71bde937 --- /dev/null +++ b/app/Http/Controllers/Admin/FlightController.php @@ -0,0 +1,178 @@ +flightRepository = $flightRepo; + } + + /** + * Display a listing of the Flight. + * + * @param Request $request + * @return Response + */ + public function index(Request $request) + { + $this->flightRepository->pushCriteria(new RequestCriteria($request)); + $flights = $this->flightRepository->all(); + + return view('admin.flights.index') + ->with('flights', $flights); + } + + /** + * Show the form for creating a new Flight. + * + * @return Response + */ + public function create() + { + return view('admin.flights.create'); + } + + /** + * Store a newly created Flight in storage. + * + * @param CreateFlightRequest $request + * + * @return Response + */ + public function store(CreateFlightRequest $request) + { + $input = $request->all(); + + $flight = $this->flightRepository->create($input); + + Flash::success('Flight saved successfully.'); + + return redirect(route('admin.flights.index')); + } + + /** + * Display the specified Flight. + * + * @param int $id + * + * @return Response + */ + public function show($id) + { + $flight = $this->flightRepository->findWithoutFail($id); + + if (empty($flight)) { + Flash::error('Flight not found'); + return redirect(route('admin.flights.index')); + } + + return view('admin.flights.show')->with('flight', $flight); + } + + /** + * Show the form for editing the specified Flight. + * + * @param int $id + * + * @return Response + */ + public function edit($id) + { + $flight = $this->flightRepository->findWithoutFail($id); + + if (empty($flight)) { + Flash::error('Flight not found'); + return redirect(route('admin.flights.index')); + } + + return view('admin.flights.edit')->with('flight', $flight); + } + + /** + * Update the specified Flight in storage. + * + * @param int $id + * @param UpdateFlightRequest $request + * + * @return Response + */ + public function update($id, UpdateFlightRequest $request) + { + $flight = $this->flightRepository->findWithoutFail($id); + + if (empty($flight)) { + Flash::error('Flight not found'); + return redirect(route('admin.flights.index')); + } + + $flight = $this->flightRepository->update($request->all(), $id); + + Flash::success('Flight updated successfully.'); + + return redirect(route('admin.flights.index')); + } + + /** + * Remove the specified Flight from storage. + * + * @param int $id + * + * @return Response + */ + public function destroy($id) + { + $flight = $this->flightRepository->findWithoutFail($id); + + if (empty($flight)) { + Flash::error('Flight not found'); + return redirect(route('admin.flights.index')); + } + + $this->flightRepository->delete($id); + + Flash::success('Flight deleted successfully.'); + return redirect(route('admin.flights.index')); + } + + public function aircraft(Request $request) + { + $id = $request->id; + + $flight = $this->flightRepository->findWithoutFail($id); + + if (empty($flight)) { + Flash::error('Flight not found'); + return redirect(route('admin.flights.index')); + } + + /** + * update specific aircraftdata + */ + if ($request->isMethod('post')) { + // add + } + + // update the pivot table with overrides for the fares + elseif ($request->isMethod('put')) { + // update + } + + // dissassociate fare from teh aircraft + elseif ($request->isMethod('delete')) { + // del + } + } +} diff --git a/app/Http/Requests/CreateFlightRequest.php b/app/Http/Requests/CreateFlightRequest.php new file mode 100644 index 00000000..aea38f6f --- /dev/null +++ b/app/Http/Requests/CreateFlightRequest.php @@ -0,0 +1,30 @@ + 'string', + 'route_code' => 'string', + 'route_leg' => 'string', + 'route' => 'string', + 'dpt_time' => 'string', + 'arr_time' => 'string', + 'notes' => 'string', + 'active' => 'boolean', + ]; + + /** + * Validation rules + * + * @var array + */ + public static $rules + = [ + 'flight_number' => 'required', + 'dpt_airport_id' => 'required', + 'arr_airport_id' => 'required', + ]; + + public function dpt_airport() + { + return $this->belongsTo('App\Models\Airport', 'dpt_airport_id'); + } + + public function arr_airport() + { + return $this->belongsTo('App\Models\Airport', 'arr_airport_id'); + } + + public function alt_airport() + { + return $this->belongsTo('App\Models\Airport', 'alt_airport_id'); + } + + public function aircraft() + { + return $this->belongsToMany('App\Models\Aircraft', 'flight_aircraft'); + } +} diff --git a/app/Repositories/FlightRepository.php b/app/Repositories/FlightRepository.php new file mode 100644 index 00000000..a982f30e --- /dev/null +++ b/app/Repositories/FlightRepository.php @@ -0,0 +1,25 @@ +increments('id'); + $table->integer('airline_id')->unsigned(); + $table->text('flight_number'); + $table->text('route_code'); + $table->text('route_leg'); + $table->integer('dpt_airport_id')->unsigned(); + $table->integer('arr_airport_id')->unsigned(); + $table->integer('alt_airport_id')->unsigned(); + $table->text('route'); + $table->text('dpt_time'); + $table->text('arr_time'); + $table->text('notes'); + $table->boolean('active'); + $table->timestamps(); + $table->softDeletes(); + }); + + Schema::create('flight_aircraft', function ($table) { + $table->increments('id'); + $table->integer('flight_id')->unsigned(); + $table->integer('aircraft_id')->unsigned(); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('flights'); + Schema::drop('flight_aircraft'); + } +} diff --git a/resources/views/admin/flights/create.blade.php b/resources/views/admin/flights/create.blade.php new file mode 100644 index 00000000..e12592d6 --- /dev/null +++ b/resources/views/admin/flights/create.blade.php @@ -0,0 +1,22 @@ +@extends('admin.app') + +@section('content') +
+

Create Flight

+
+
+ @include('adminlte-templates::common.errors') +
+ +
+
+ {!! Form::open(['route' => 'admin.flights.store']) !!} + + @include('admin.flights.fields') + + {!! Form::close() !!} +
+
+
+
+@endsection diff --git a/resources/views/admin/flights/edit.blade.php b/resources/views/admin/flights/edit.blade.php new file mode 100644 index 00000000..86a5b0bf --- /dev/null +++ b/resources/views/admin/flights/edit.blade.php @@ -0,0 +1,21 @@ +@extends('admin.app') + +@section('content') +
+

Edit {!! $flight->airline->name !!}{!! $flight->number !!}

+
+
+ @include('adminlte-templates::common.errors') +
+
+
+ {!! Form::model($flight, ['route' => ['admin.flights.update', $flight->id], 'method' => 'patch']) !!} + + @include('admin.flights.fields') + + {!! Form::close() !!} +
+
+
+
+@endsection diff --git a/resources/views/admin/flights/fields.blade.php b/resources/views/admin/flights/fields.blade.php new file mode 100644 index 00000000..61e8dc1b --- /dev/null +++ b/resources/views/admin/flights/fields.blade.php @@ -0,0 +1,77 @@ + +
+ {!! Form::label('airline_id', 'Airline:') !!} + {!! Form::text('airline_id', null, ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::label('flight_number', 'Flight Number:') !!} + {!! Form::text('flight_number', null, ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::label('route_code', 'Route Code:') !!} + {!! Form::text('route_code', null, ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::label('route_leg', 'Route Leg:') !!} + {!! Form::text('route_leg', null, ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::label('dpt_airport_id', 'Dpt Airport Id:') !!} + {!! Form::text('dpt_airport_id', null, ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::label('arr_airport_id', 'Arr Airport Id:') !!} + {!! Form::text('arr_airport_id', null, ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::label('alt_airport_id', 'Alt Airport Id:') !!} + {!! Form::text('alt_airport_id', null, ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::label('route', 'Route:') !!} + {!! Form::text('route', null, ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::label('dpt_time', 'Dpt Time:') !!} + {!! Form::text('dpt_time', null, ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::label('arr_time', 'Arr Time:') !!} + {!! Form::text('arr_time', null, ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::label('notes', 'Notes:') !!} + {!! Form::text('notes', null, ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::label('active', 'Active:') !!} + {!! Form::text('active', null, ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::submit('Save', ['class' => 'btn btn-primary']) !!} + Cancel +
diff --git a/resources/views/admin/flights/index.blade.php b/resources/views/admin/flights/index.blade.php new file mode 100644 index 00000000..aadbe75d --- /dev/null +++ b/resources/views/admin/flights/index.blade.php @@ -0,0 +1,23 @@ +@extends('admin.app') + +@section('content') +
+

Flights

+

+ Add New +

+
+
+
+ + @include('flash::message') + +
+
+
+ @include('admin.flights.table') +
+
+
+@endsection + diff --git a/resources/views/admin/flights/show.blade.php b/resources/views/admin/flights/show.blade.php new file mode 100644 index 00000000..b5774eaa --- /dev/null +++ b/resources/views/admin/flights/show.blade.php @@ -0,0 +1,17 @@ +@extends('admin.app') + +@section('content') +
+

Flights

+
+
+
+
+
+ @include('admin.flights.show_fields') + Back +
+
+
+
+@endsection diff --git a/resources/views/admin/flights/show_fields.blade.php b/resources/views/admin/flights/show_fields.blade.php new file mode 100644 index 00000000..d58f7d41 --- /dev/null +++ b/resources/views/admin/flights/show_fields.blade.php @@ -0,0 +1,90 @@ + +
+ {!! Form::label('id', 'Id:') !!} +

{!! $flight->id !!}

+
+ + +
+ {!! Form::label('airline_id', 'Airline Id:') !!} +

{!! $flight->airline_id !!}

+
+ + +
+ {!! Form::label('flight_number', 'Flight Number:') !!} +

{!! $flight->flight_number !!}

+
+ + +
+ {!! Form::label('route_code', 'Route Code:') !!} +

{!! $flight->route_code !!}

+
+ + +
+ {!! Form::label('route_leg', 'Route Leg:') !!} +

{!! $flight->route_leg !!}

+
+ + +
+ {!! Form::label('dpt_airport_id', 'Dpt Airport Id:') !!} +

{!! $flight->dpt_airport_id !!}

+
+ + +
+ {!! Form::label('arr_airport_id', 'Arr Airport Id:') !!} +

{!! $flight->arr_airport_id !!}

+
+ + +
+ {!! Form::label('alt_airport_id', 'Alt Airport Id:') !!} +

{!! $flight->alt_airport_id !!}

+
+ + +
+ {!! Form::label('route', 'Route:') !!} +

{!! $flight->route !!}

+
+ + +
+ {!! Form::label('dpt_time', 'Dpt Time:') !!} +

{!! $flight->dpt_time !!}

+
+ + +
+ {!! Form::label('arr_time', 'Arr Time:') !!} +

{!! $flight->arr_time !!}

+
+ + +
+ {!! Form::label('notes', 'Notes:') !!} +

{!! $flight->notes !!}

+
+ + +
+ {!! Form::label('active', 'Active:') !!} +

{!! $flight->active !!}

+
+ + +
+ {!! Form::label('created_at', 'Created At:') !!} +

{!! $flight->created_at !!}

+
+ + +
+ {!! Form::label('updated_at', 'Updated At:') !!} +

{!! $flight->updated_at !!}

+
+ diff --git a/resources/views/admin/flights/table.blade.php b/resources/views/admin/flights/table.blade.php new file mode 100644 index 00000000..c6322247 --- /dev/null +++ b/resources/views/admin/flights/table.blade.php @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + @foreach($flights as $flight) + + + + + + + + + + + + + @endforeach + +
Flight #DepArrAltRouteDpt TimeArr TimeNotesActiveAction
+ {!! $flight->airline_id !!}/{!! $flight->flight_number !!} + (C: {!! $flight->route_code !!} L: {!! $flight->route_leg !!}) + {!! $flight->dpt_airport->icao !!}{!! $flight->arr_airport->icao !!}{!! $flight->alt_airport->icao !!}{!! $flight->route !!}{!! $flight->dpt_time !!}{!! $flight->arr_time !!}{!! $flight->notes !!}{!! $flight->active !!} + {!! Form::open(['route' => ['admin.flights.destroy', $flight->id], 'method' => 'delete']) !!} +
+ + + {!! Form::button('', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure?')"]) !!} +
+ {!! Form::close() !!} +
diff --git a/resources/views/admin/menu.blade.php b/resources/views/admin/menu.blade.php index bae4b099..6355f6f7 100644 --- a/resources/views/admin/menu.blade.php +++ b/resources/views/admin/menu.blade.php @@ -7,6 +7,7 @@ 3 +
  •  flights
  •  fleet
  •  fares
  • diff --git a/routes/web.php b/routes/web.php index c6f6ebf6..993464ac 100755 --- a/routes/web.php +++ b/routes/web.php @@ -34,6 +34,11 @@ Route::group([ 'aircraft/{id}/fares', 'AircraftController@fares'); + Route::resource('flights', 'FlightController'); + Route::match(['get', 'post', 'put', 'delete'], + 'flights/{id}/aircraft', + 'FlightController@aircraft'); + Route::get('', ['uses' => 'DashboardController@index']); Route::get('/', ['uses' => 'DashboardController@index']); Route::get('/dashboard', ['uses' => 'DashboardController@index','name' => 'dashboard']);