#14 initial scaffolding for adding flights/schedules

This commit is contained in:
Nabeel Shahzad
2017-06-17 17:25:36 -05:00
parent d52f1cec05
commit f4e7eef40c
15 changed files with 697 additions and 0 deletions

View File

@@ -0,0 +1,178 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\CreateFlightRequest;
use App\Http\Requests\UpdateFlightRequest;
use App\Repositories\FlightRepository;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;
class FlightController extends BaseController
{
/** @var FlightRepository */
private $flightRepository;
public function __construct(FlightRepository $flightRepo)
{
$this->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
}
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
use App\Models\Flight;
class CreateFlightRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return Flight::$rules;
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
use App\Models\Flight;
class UpdateFlightRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return Flight::$rules;
}
}

85
app/Models/Flight.php Normal file
View File

@@ -0,0 +1,85 @@
<?php
namespace App\Models;
use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class Flight
*
* @package App\Models
*/
class Flight extends Model
{
use SoftDeletes;
public $table = 'flights';
protected $dates = ['deleted_at'];
public $fillable
= [
'airline_id',
'flight_number',
'route_code',
'route_leg',
'dpt_airport_id',
'arr_airport_id',
'alt_airport_id',
'route',
'dpt_time',
'arr_time',
'notes',
'active',
];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts
= [
'flight_number' => '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');
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Repositories;
use App\Models\Flight;
use InfyOm\Generator\Common\BaseRepository;
class FlightRepository extends BaseRepository
{
/**
* @var array
*/
protected $fieldSearchable = [
'dpt_airport_id',
'arr_airport_id'
];
/**
* Configure the Model
**/
public function model()
{
return Flight::class;
}
}

View File

@@ -0,0 +1,52 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateFlightsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('flights', function (Blueprint $table) {
$table->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');
}
}

View File

@@ -0,0 +1,22 @@
@extends('admin.app')
@section('content')
<section class="content-header">
<h1>Create Flight</h1>
</section>
<div class="content">
@include('adminlte-templates::common.errors')
<div class="box box-primary">
<div class="box-body">
<div class="row">
{!! Form::open(['route' => 'admin.flights.store']) !!}
@include('admin.flights.fields')
{!! Form::close() !!}
</div>
</div>
</div>
</div>
@endsection

View File

@@ -0,0 +1,21 @@
@extends('admin.app')
@section('content')
<section class="content-header">
<h1>Edit {!! $flight->airline->name !!}{!! $flight->number !!}</h1>
</section>
<div class="content">
@include('adminlte-templates::common.errors')
<div class="box box-primary">
<div class="box-body">
<div class="row">
{!! Form::model($flight, ['route' => ['admin.flights.update', $flight->id], 'method' => 'patch']) !!}
@include('admin.flights.fields')
{!! Form::close() !!}
</div>
</div>
</div>
</div>
@endsection

View File

@@ -0,0 +1,77 @@
<!-- Airline Id Field -->
<div class="form-group col-sm-6">
{!! Form::label('airline_id', 'Airline:') !!}
{!! Form::text('airline_id', null, ['class' => 'form-control']) !!}
</div>
<!-- Flight Number Field -->
<div class="form-group col-sm-6">
{!! Form::label('flight_number', 'Flight Number:') !!}
{!! Form::text('flight_number', null, ['class' => 'form-control']) !!}
</div>
<!-- Route Code Field -->
<div class="form-group col-sm-6">
{!! Form::label('route_code', 'Route Code:') !!}
{!! Form::text('route_code', null, ['class' => 'form-control']) !!}
</div>
<!-- Route Leg Field -->
<div class="form-group col-sm-6">
{!! Form::label('route_leg', 'Route Leg:') !!}
{!! Form::text('route_leg', null, ['class' => 'form-control']) !!}
</div>
<!-- Dpt Airport Id Field -->
<div class="form-group col-sm-6">
{!! Form::label('dpt_airport_id', 'Dpt Airport Id:') !!}
{!! Form::text('dpt_airport_id', null, ['class' => 'form-control']) !!}
</div>
<!-- Arr Airport Id Field -->
<div class="form-group col-sm-6">
{!! Form::label('arr_airport_id', 'Arr Airport Id:') !!}
{!! Form::text('arr_airport_id', null, ['class' => 'form-control']) !!}
</div>
<!-- Alt Airport Id Field -->
<div class="form-group col-sm-6">
{!! Form::label('alt_airport_id', 'Alt Airport Id:') !!}
{!! Form::text('alt_airport_id', null, ['class' => 'form-control']) !!}
</div>
<!-- Route Field -->
<div class="form-group col-sm-6">
{!! Form::label('route', 'Route:') !!}
{!! Form::text('route', null, ['class' => 'form-control']) !!}
</div>
<!-- Dpt Time Field -->
<div class="form-group col-sm-6">
{!! Form::label('dpt_time', 'Dpt Time:') !!}
{!! Form::text('dpt_time', null, ['class' => 'form-control']) !!}
</div>
<!-- Arr Time Field -->
<div class="form-group col-sm-6">
{!! Form::label('arr_time', 'Arr Time:') !!}
{!! Form::text('arr_time', null, ['class' => 'form-control']) !!}
</div>
<!-- Notes Field -->
<div class="form-group col-sm-6">
{!! Form::label('notes', 'Notes:') !!}
{!! Form::text('notes', null, ['class' => 'form-control']) !!}
</div>
<!-- Active Field -->
<div class="form-group col-sm-6">
{!! Form::label('active', 'Active:') !!}
{!! Form::text('active', null, ['class' => 'form-control']) !!}
</div>
<!-- Submit Field -->
<div class="form-group col-sm-12">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
<a href="{!! route('admin.flights.index') !!}" class="btn btn-default">Cancel</a>
</div>

View File

@@ -0,0 +1,23 @@
@extends('admin.app')
@section('content')
<section class="content-header">
<h1 class="pull-left">Flights</h1>
<h1 class="pull-right">
<a class="btn btn-primary pull-right" style="margin-top: -10px;margin-bottom: 5px" href="{!! route('admin.flights.create') !!}">Add New</a>
</h1>
</section>
<div class="content">
<div class="clearfix"></div>
@include('flash::message')
<div class="clearfix"></div>
<div class="box box-primary">
<div class="box-body">
@include('admin.flights.table')
</div>
</div>
</div>
@endsection

View File

@@ -0,0 +1,17 @@
@extends('admin.app')
@section('content')
<section class="content-header">
<h1>Flights</h1>
</section>
<div class="content">
<div class="box box-primary">
<div class="box-body">
<div class="row" style="padding-left: 20px">
@include('admin.flights.show_fields')
<a href="{!! route('admin.flights.index') !!}" class="btn btn-default">Back</a>
</div>
</div>
</div>
</div>
@endsection

View File

@@ -0,0 +1,90 @@
<!-- Id Field -->
<div class="form-group">
{!! Form::label('id', 'Id:') !!}
<p>{!! $flight->id !!}</p>
</div>
<!-- Airline Id Field -->
<div class="form-group">
{!! Form::label('airline_id', 'Airline Id:') !!}
<p>{!! $flight->airline_id !!}</p>
</div>
<!-- Flight Number Field -->
<div class="form-group">
{!! Form::label('flight_number', 'Flight Number:') !!}
<p>{!! $flight->flight_number !!}</p>
</div>
<!-- Route Code Field -->
<div class="form-group">
{!! Form::label('route_code', 'Route Code:') !!}
<p>{!! $flight->route_code !!}</p>
</div>
<!-- Route Leg Field -->
<div class="form-group">
{!! Form::label('route_leg', 'Route Leg:') !!}
<p>{!! $flight->route_leg !!}</p>
</div>
<!-- Dpt Airport Id Field -->
<div class="form-group">
{!! Form::label('dpt_airport_id', 'Dpt Airport Id:') !!}
<p>{!! $flight->dpt_airport_id !!}</p>
</div>
<!-- Arr Airport Id Field -->
<div class="form-group">
{!! Form::label('arr_airport_id', 'Arr Airport Id:') !!}
<p>{!! $flight->arr_airport_id !!}</p>
</div>
<!-- Alt Airport Id Field -->
<div class="form-group">
{!! Form::label('alt_airport_id', 'Alt Airport Id:') !!}
<p>{!! $flight->alt_airport_id !!}</p>
</div>
<!-- Route Field -->
<div class="form-group">
{!! Form::label('route', 'Route:') !!}
<p>{!! $flight->route !!}</p>
</div>
<!-- Dpt Time Field -->
<div class="form-group">
{!! Form::label('dpt_time', 'Dpt Time:') !!}
<p>{!! $flight->dpt_time !!}</p>
</div>
<!-- Arr Time Field -->
<div class="form-group">
{!! Form::label('arr_time', 'Arr Time:') !!}
<p>{!! $flight->arr_time !!}</p>
</div>
<!-- Notes Field -->
<div class="form-group">
{!! Form::label('notes', 'Notes:') !!}
<p>{!! $flight->notes !!}</p>
</div>
<!-- Active Field -->
<div class="form-group">
{!! Form::label('active', 'Active:') !!}
<p>{!! $flight->active !!}</p>
</div>
<!-- Created At Field -->
<div class="form-group">
{!! Form::label('created_at', 'Created At:') !!}
<p>{!! $flight->created_at !!}</p>
</div>
<!-- Updated At Field -->
<div class="form-group">
{!! Form::label('updated_at', 'Updated At:') !!}
<p>{!! $flight->updated_at !!}</p>
</div>

View File

@@ -0,0 +1,41 @@
<table class="table table-responsive" id="flights-table">
<thead>
<th>Flight #</th>
<th>Dep</th>
<th>Arr</th>
<th>Alt</th>
<th>Route</th>
<th>Dpt Time</th>
<th>Arr Time</th>
<th>Notes</th>
<th>Active</th>
<th colspan="3">Action</th>
</thead>
<tbody>
@foreach($flights as $flight)
<tr>
<td>
{!! $flight->airline_id !!}/{!! $flight->flight_number !!}
(C: {!! $flight->route_code !!} L: {!! $flight->route_leg !!})
</td>
<td>{!! $flight->dpt_airport->icao !!}</td>
<td>{!! $flight->arr_airport->icao !!}</td>
<td>{!! $flight->alt_airport->icao !!}</td>
<td>{!! $flight->route !!}</td>
<td>{!! $flight->dpt_time !!}</td>
<td>{!! $flight->arr_time !!}</td>
<td>{!! $flight->notes !!}</td>
<td>{!! $flight->active !!}</td>
<td>
{!! Form::open(['route' => ['admin.flights.destroy', $flight->id], 'method' => 'delete']) !!}
<div class='btn-group'>
<a href="{!! route('admin.flights.show', [$flight->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-eye-open"></i></a>
<a href="{!! route('admin.flights.edit', [$flight->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-edit"></i></a>
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure?')"]) !!}
</div>
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>

View File

@@ -7,6 +7,7 @@
<span data-toggle="tooltip" title="3 New" class="badge bg-light-blue pull-right">3</span>
</a>
</li>
<li><a href="{!! url('/admin/flights') !!}"><i class="fa fa-map"></i>&nbsp;flights</a></li>
<li><a href="{!! url('/admin/aircraft') !!}"><i class="fa fa-plane" aria-hidden="true"></i>&nbsp;fleet</a></li>
<li><a href="{!! url('/admin/fares') !!}"><i class="fa fa-dollar"></i>&nbsp;fares</a></li>

View File

@@ -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']);