#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;
}
}