diff --git a/app/Http/Controllers/Admin/FlightController.php b/app/Http/Controllers/Admin/FlightController.php
index 5b5a950d..135763d2 100644
--- a/app/Http/Controllers/Admin/FlightController.php
+++ b/app/Http/Controllers/Admin/FlightController.php
@@ -7,6 +7,8 @@ use App\Models\FlightFields;
use App\Models\Airport;
use App\Http\Requests\CreateFlightRequest;
use App\Http\Requests\UpdateFlightRequest;
+use App\Repositories\AirlineRepository;
+use App\Repositories\AirportRepository;
use App\Repositories\FlightRepository;
use App\Repositories\SubfleetRepository;
use Illuminate\Http\Request;
@@ -16,15 +18,15 @@ use Response;
class FlightController extends BaseController
{
- /** @var FlightRepository */
- private $flightRepository, $subfleetRepo;
-
public function __construct(
+ AirlineRepository $airlineRepo,
+ AirportRepository $airportRepo,
FlightRepository $flightRepo,
SubfleetRepository $subfleetRepo
- )
- {
- $this->flightRepository = $flightRepo;
+ ) {
+ $this->airlineRepo = $airlineRepo;
+ $this->airportRepo = $airportRepo;
+ $this->flightRepo = $flightRepo;
$this->subfleetRepo = $subfleetRepo;
}
@@ -51,8 +53,8 @@ class FlightController extends BaseController
*/
public function index(Request $request)
{
- $this->flightRepository->pushCriteria(new RequestCriteria($request));
- $flights = $this->flightRepository->all();
+ $this->flightRepo->pushCriteria(new RequestCriteria($request));
+ $flights = $this->flightRepo->paginate(10);
return view('admin.flights.index', [
'flights' => $flights,
]);
@@ -79,7 +81,7 @@ class FlightController extends BaseController
{
$input = $request->all();
- $flight = $this->flightRepository->create($input);
+ $flight = $this->flightRepo->create($input);
Flash::success('Flight saved successfully.');
return redirect(route('admin.flights.index'));
@@ -94,7 +96,7 @@ class FlightController extends BaseController
*/
public function show($id)
{
- $flight = $this->flightRepository->findWithoutFail($id);
+ $flight = $this->flightRepo->findWithoutFail($id);
if (empty($flight)) {
Flash::error('Flight not found');
@@ -117,7 +119,7 @@ class FlightController extends BaseController
*/
public function edit($id)
{
- $flight = $this->flightRepository->findWithoutFail($id);
+ $flight = $this->flightRepo->findWithoutFail($id);
if (empty($flight)) {
Flash::error('Flight not found');
@@ -127,8 +129,8 @@ class FlightController extends BaseController
$avail_subfleets = $this->getAvailSubfleets($flight);
return view('admin.flights.edit', [
'flight' => $flight,
- 'airlines' => Airline::all()->pluck('name', 'id'),
- 'airports' => Airport::all()->pluck('icao', 'id'),
+ 'airlines' => $this->airlineRepo->all()->pluck('name', 'id'),
+ 'airports' => $this->airportRepo->all()->pluck('icao', 'icao'),
'avail_subfleets' => $avail_subfleets,
]);
}
@@ -143,14 +145,14 @@ class FlightController extends BaseController
*/
public function update($id, UpdateFlightRequest $request)
{
- $flight = $this->flightRepository->findWithoutFail($id);
+ $flight = $this->flightRepo->findWithoutFail($id);
if (empty($flight)) {
Flash::error('Flight not found');
return redirect(route('admin.flights.index'));
}
- $flight = $this->flightRepository->update($request->all(), $id);
+ $flight = $this->flightRepo->update($request->all(), $id);
Flash::success('Flight updated successfully.');
return redirect(route('admin.flights.index'));
@@ -165,14 +167,14 @@ class FlightController extends BaseController
*/
public function destroy($id)
{
- $flight = $this->flightRepository->findWithoutFail($id);
+ $flight = $this->flightRepo->findWithoutFail($id);
if (empty($flight)) {
Flash::error('Flight not found');
return redirect(route('admin.flights.index'));
}
- $this->flightRepository->delete($id);
+ $this->flightRepo->delete($id);
Flash::success('Flight deleted successfully.');
return redirect(route('admin.flights.index'));
@@ -190,7 +192,7 @@ class FlightController extends BaseController
{
$id = $request->id;
- $flight = $this->flightRepository->findWithoutFail($id);
+ $flight = $this->flightRepo->findWithoutFail($id);
if (empty($flight)) {
Flash::error('Flight not found');
return redirect(route('admin.flights.index'));
@@ -233,7 +235,7 @@ class FlightController extends BaseController
{
$id = $request->id;
- $flight = $this->flightRepository->findWithoutFail($id);
+ $flight = $this->flightRepo->findWithoutFail($id);
if (empty($flight)) {
Flash::error('Flight not found');
return redirect(route('admin.flights.index'));
diff --git a/app/Http/Controllers/Frontend/PirepController.php b/app/Http/Controllers/Frontend/PirepController.php
index b177222b..f97d518f 100644
--- a/app/Http/Controllers/Frontend/PirepController.php
+++ b/app/Http/Controllers/Frontend/PirepController.php
@@ -5,15 +5,15 @@ namespace App\Http\Controllers\Frontend;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
-use App\Models\Airline;
-use App\Models\Airport;
use App\Models\Pirep;
use App\Models\PirepField;
use App\Http\Controllers\Controller;
use App\Repositories\AirlineRepository;
use App\Repositories\AircraftRepository;
+use App\Repositories\AirportRepository;
use App\Repositories\PirepRepository;
+use App\Repositories\PirepFieldRepository;
class PirepController extends Controller
@@ -21,20 +21,25 @@ class PirepController extends Controller
public function __construct(
AirlineRepository $airlineRepo,
PirepRepository $pirepRepo,
- AircraftRepository $aircraftRepo)
- {
+ AircraftRepository $aircraftRepo,
+ AirportRepository $airportRepo,
+ PirepFieldRepository $pirepFieldRepo
+ ) {
+ parent::__construct();
$this->airlineRepo = $airlineRepo;
$this->aircraftRepo = $aircraftRepo;
$this->pirepRepo = $pirepRepo;
+ $this->airportRepo = $airportRepo;
+ $this->pirepFieldRepo = $pirepFieldRepo;
}
public function airportList()
{
# TODO: Cache
$retval = [];
- $airports = Airport::all();
+ $airports = $this->airportRepo->all();
foreach($airports as $airport) {
- $retval[$airport->id] = $airport->icao.' - '.$airport->name;
+ $retval[$airport->icao] = $airport->icao.' - '.$airport->name;
}
return $retval;
@@ -55,9 +60,10 @@ class PirepController extends Controller
public function index(Request $request)
{
$user = Auth::user();
- $pireps = Pirep::where('user_id', $user->id)
- ->orderBy('created_at', 'desc')
- ->get();
+ $pireps = $this->pirepRepo
+ ->where('user_id', $user->id)
+ ->orderBy('created_at', 'desc')
+ ->get();
return $this->view('pireps.index', [
'user' => $user,
@@ -72,9 +78,9 @@ class PirepController extends Controller
return $this->view('pireps.create', [
'airports' => $airports,
- 'airlines' => Airline::all()->pluck('name', 'id'),
+ 'airlines' => $this->airlineRepo->all()->pluck('name', 'id'),
'aircraft' => $aircraft,
- 'pirepfields' => PirepField::all(),
+ 'pirepfields' => $this->pirepFieldRepo->all(),
'fieldvalues' => [],
]);
}
diff --git a/app/Models/Airport.php b/app/Models/Airport.php
index f41b7e12..429322d9 100644
--- a/app/Models/Airport.php
+++ b/app/Models/Airport.php
@@ -11,9 +11,10 @@ use Eloquent as Model;
class Airport extends Model
{
public $table = 'airports';
- protected $dates = ['deleted_at'];
+ public $timestamps = false;
public $fillable = [
+ 'id',
'icao',
'name',
'location',
@@ -24,30 +25,28 @@ class Airport extends Model
'fuel_mogas_cost',
];
- /**
- * The attributes that should be casted to native types.
- *
- * @var array
- */
- protected $casts = [
-
- ];
-
/**
* Validation rules
*
* @var array
*/
public static $rules = [
- 'icao' => 'required|unique:airports'
+ #'icao' => 'required|unique:airports'
];
- public function save(array $options = [])
- {
- if(in_array('icao', $options)) {
- $options['icao'] = strtoupper($options['icao']);
- }
+ /**
+ * Some fancy callbacks
+ */
+ protected static function boot() {
- return parent::save($options);
+ parent::boot();
+
+ /**
+ * Make sure the ID is set to the ICAO
+ */
+ static::creating(function (Airport $model) {
+ $model->icao = strtoupper($model->icao);
+ $model->id = $model->icao;
+ });
}
}
diff --git a/app/Repositories/AircraftRepository.php b/app/Repositories/AircraftRepository.php
index 6b1e8b11..cc45122b 100644
--- a/app/Repositories/AircraftRepository.php
+++ b/app/Repositories/AircraftRepository.php
@@ -3,9 +3,13 @@
namespace App\Repositories;
use App\Models\Aircraft;
+use Prettus\Repository\Contracts\CacheableInterface;
+use Prettus\Repository\Traits\CacheableRepository;
-class AircraftRepository extends BaseRepository
+class AircraftRepository extends BaseRepository implements CacheableInterface
{
+ use CacheableRepository;
+
/**
* @var array
*/
diff --git a/app/Repositories/AirlineRepository.php b/app/Repositories/AirlineRepository.php
index 417e6678..423ddaf7 100644
--- a/app/Repositories/AirlineRepository.php
+++ b/app/Repositories/AirlineRepository.php
@@ -3,9 +3,14 @@
namespace App\Repositories;
use App\Models\Airline;
+use Prettus\Repository\Contracts\CacheableInterface;
+use Prettus\Repository\Traits\CacheableRepository;
-class AirlineRepository extends BaseRepository
+
+class AirlineRepository extends BaseRepository implements CacheableInterface
{
+ use CacheableRepository;
+
/**
* @var array
*/
diff --git a/app/Repositories/AirportRepository.php b/app/Repositories/AirportRepository.php
index b9de4072..d1d23002 100644
--- a/app/Repositories/AirportRepository.php
+++ b/app/Repositories/AirportRepository.php
@@ -3,10 +3,14 @@
namespace App\Repositories;
use App\Models\Airport;
+use Prettus\Repository\Contracts\CacheableInterface;
+use Prettus\Repository\Traits\CacheableRepository;
-class AirportRepository extends BaseRepository
+class AirportRepository extends BaseRepository implements CacheableInterface
{
+ use CacheableRepository;
+
/**
* @var array
*/
@@ -21,4 +25,10 @@ class AirportRepository extends BaseRepository
{
return Airport::class;
}
+
+ public function create(array $attributes)
+ {
+ //$attributes['id'] = $attributes['icao'];
+ return parent::create($attributes);
+ }
}
diff --git a/app/Repositories/FlightRepository.php b/app/Repositories/FlightRepository.php
index ddba9bd7..4840bdce 100644
--- a/app/Repositories/FlightRepository.php
+++ b/app/Repositories/FlightRepository.php
@@ -3,15 +3,22 @@
namespace App\Repositories;
use App\Models\Flight;
+use Prettus\Repository\Contracts\CacheableInterface;
+use Prettus\Repository\Traits\CacheableRepository;
-class FlightRepository extends BaseRepository
+class FlightRepository extends BaseRepository implements CacheableInterface
{
+ use CacheableRepository;
+
/**
* @var array
*/
protected $fieldSearchable = [
+ 'arr_airport_id',
'dpt_airport_id',
- 'arr_airport_id'
+ 'flight_number' => 'like',
+ 'route' => 'like',
+ 'notes' => 'like',
];
/**
diff --git a/app/Repositories/RankRepository.php b/app/Repositories/RankRepository.php
index 2e2c0075..961f43ec 100644
--- a/app/Repositories/RankRepository.php
+++ b/app/Repositories/RankRepository.php
@@ -3,9 +3,13 @@
namespace App\Repositories;
use App\Models\Rank;
+use Prettus\Repository\Contracts\CacheableInterface;
+use Prettus\Repository\Traits\CacheableRepository;
-class RankRepository extends BaseRepository
+class RankRepository extends BaseRepository implements CacheableInterface
{
+ use CacheableRepository;
+
/**
* @var array
*/
diff --git a/database/migrations/2017_06_08_0000_create_users_table.php b/database/migrations/2017_06_08_0000_create_users_table.php
index fb540c71..d1041948 100755
--- a/database/migrations/2017_06_08_0000_create_users_table.php
+++ b/database/migrations/2017_06_08_0000_create_users_table.php
@@ -20,8 +20,8 @@ class CreateUsersTable extends Migration
$table->string('password');
$table->integer('airline_id')->nullable()->unsigned();
$table->integer('rank_id')->nullable()->unsigned();
- $table->integer('home_airport_id')->nullable()->unsigned();
- $table->integer('curr_airport_id')->nullable()->unsigned();
+ $table->string('home_airport_id', 5)->nullable();
+ $table->string('curr_airport_id', 5)->nullable();
$table->uuid('last_pirep_id')->nullable();
$table->bigInteger('flights')->unsigned()->default(0);
$table->bigInteger('flight_time')->unsigned()->default(0);
diff --git a/database/migrations/2017_06_09_010621_create_aircrafts_table.php b/database/migrations/2017_06_09_010621_create_aircrafts_table.php
index ca610cf4..661be527 100644
--- a/database/migrations/2017_06_09_010621_create_aircrafts_table.php
+++ b/database/migrations/2017_06_09_010621_create_aircrafts_table.php
@@ -10,7 +10,7 @@ class CreateAircraftsTable extends Migration
Schema::create('aircraft', function (Blueprint $table) {
$table->increments('id');
$table->integer('subfleet_id')->unsigned();
- $table->integer('airport_id')->unsigned()->nullable();
+ $table->string('airport_id', 5)->nullable();
$table->string('hex_code', 10)->nullable();
$table->string('name', 50);
$table->string('registration', 10)->nullable();
diff --git a/database/migrations/2017_06_11_135707_create_airports_table.php b/database/migrations/2017_06_11_135707_create_airports_table.php
index dfed5fe6..12787016 100644
--- a/database/migrations/2017_06_11_135707_create_airports_table.php
+++ b/database/migrations/2017_06_11_135707_create_airports_table.php
@@ -14,19 +14,17 @@ class CreateAirportsTable extends Migration
public function up()
{
Schema::create('airports', function (Blueprint $table) {
- $table->bigIncrements('id');
- $table->string('icao', 5)->unique();
+// $table->bigIncrements('id');
+ $table->string('id', 5)->primary();
+ $table->string('icao', 5);
$table->string('name', 50);
$table->string('location', 50)->nullable();
$table->string('country', 50)->nullable();
$table->double('fuel_100ll_cost', 19, 2)->default(0);
$table->double('fuel_jeta_cost', 19, 2)->default(0);
$table->double('fuel_mogas_cost', 19, 2)->default(0);
- $table->float('lat', 7, 4)->default(0.0);
- $table->float('lon', 7, 4)->default(0.0);
- $table->timestamps();
-
- $table->index('icao');
+ $table->float('lat', 7, 4)->default(0.0)->nullable();
+ $table->float('lon', 7, 4)->default(0.0)->nullable();
});
}
diff --git a/database/migrations/2017_06_17_214650_create_flights_table.php b/database/migrations/2017_06_17_214650_create_flights_table.php
index b6b3143f..80866634 100644
--- a/database/migrations/2017_06_17_214650_create_flights_table.php
+++ b/database/migrations/2017_06_17_214650_create_flights_table.php
@@ -19,9 +19,9 @@ class CreateFlightsTable extends Migration
$table->string('flight_number', 10);
$table->string('route_code', 5)->nullable();
$table->string('route_leg', 5)->nullable();
- $table->integer('dpt_airport_id')->unsigned();
- $table->integer('arr_airport_id')->unsigned();
- $table->integer('alt_airport_id')->unsigned()->nullable();
+ $table->string('dpt_airport_id', 5);
+ $table->string('arr_airport_id', 5);
+ $table->string('alt_airport_id', 5)->nullable();
$table->text('route')->nullable();
$table->text('dpt_time', 10)->nullable();
$table->text('arr_time', 10)->nullable();
diff --git a/database/migrations/2017_06_28_195426_create_pireps_table.php b/database/migrations/2017_06_28_195426_create_pireps_table.php
index 5ee6b3cb..e6ccb705 100644
--- a/database/migrations/2017_06_28_195426_create_pireps_table.php
+++ b/database/migrations/2017_06_28_195426_create_pireps_table.php
@@ -22,8 +22,8 @@ class CreatePirepsTable extends Migration
$table->string('flight_number', 10)->nullable();
$table->string('route_code', 5)->nullable();
$table->string('route_leg', 5)->nullable();
- $table->integer('dpt_airport_id')->unsigned();
- $table->integer('arr_airport_id')->unsigned();
+ $table->string('dpt_airport_id', 5)->unsigned();
+ $table->string('arr_airport_id', 5)->unsigned();
$table->double('flight_time', 19, 2)->unsigned();
$table->double('gross_weight', 19, 2)->nullable();
$table->double('fuel_used', 19, 2)->nullable();
diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php
index e6b940d6..b63352b9 100755
--- a/database/seeds/DatabaseSeeder.php
+++ b/database/seeds/DatabaseSeeder.php
@@ -13,6 +13,7 @@ class DatabaseSeeder extends Seeder
{
$env = App::environment();
$path = database_path('seeds/'.$env.'.yml');
+ print "Seeding seeds/$env.yml";
if(!file_exists($path)) {
$path = database_path('seeds/prod.yml');
}
diff --git a/database/seeds/dev.yml b/database/seeds/dev.yml
index 6e257603..739e9cc6 100644
--- a/database/seeds/dev.yml
+++ b/database/seeds/dev.yml
@@ -14,8 +14,8 @@ users:
password: admin
rank_id: 1
airline_id: 1
- home_airport_id: 1
- curr_airport_id: 2
+ home_airport_id: KAUS
+ curr_airport_id: KJFK
flights: 1
flight_time: 43200
created_at: now
@@ -27,8 +27,8 @@ users:
password: admin
rank_id: 1
airline_id: 1
- home_airport_id: 2
- curr_airport_id: 2
+ home_airport_id: KJFK
+ curr_airport_id: KJFK
flights: 1
flight_time: 43200
created_at: now
@@ -40,8 +40,8 @@ users:
password: admin
rank_id: 1
airline_id: 1
- home_airport_id: 2
- curr_airport_id: 2
+ home_airport_id: KJFK
+ curr_airport_id: KAUS
flights: 1
flight_time: 43200
created_at: now
@@ -88,19 +88,19 @@ airlines:
updated_at: now
airports:
- - id: 1
+ - id: KAUS
icao: KAUS
name: Austin-Bergstrom
location: Austin, Texas, USA
lat: 30.1945278
lon: -97.6698889
- - id: 2
+ - id: KJFK
icao: KJFK
name: John F Kennedy
location: New York, New York, USA
lat: 40.6399257
lon: -73.7786950
- - id: 3
+ - id: EGLL
icao: EGLL
name: London Heathrow
location: London, England
@@ -186,27 +186,123 @@ flights:
- id: flightid_1
airline_id: 1
flight_number: 100
- dpt_airport_id: 1
- arr_airport_id: 2
+ dpt_airport_id: KAUS
+ arr_airport_id: KJFK
route: KAUS KJFK
dpt_time: 6PM CST
arr_time: 11PM EST
- id: flightid_2
airline_id: 1
flight_number: 101
- dpt_airport_id: 2
- arr_airport_id: 1
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
dpt_time: 9AM EST
arr_time: 12PM CST
route: KJFK KAUS
- id: flightid_3
airline_id: 1
flight_number: 200
- dpt_airport_id: 2
- arr_airport_id: 3
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
dpt_time: 9AM EST
arr_time: 12PM CST
route: KJFK KAUS
+ - id: flightid_4
+ airline_id: 1
+ flight_number: 201
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
+ dpt_time: 10AM EST
+ arr_time: 1PM CST
+ route: KJFK KAUS
+ - id: flightid_5
+ airline_id: 1
+ flight_number: 202
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
+ dpt_time: 11AM EST
+ arr_time: 2PM CST
+ route: KJFK KAUS
+ - id: flightid_6
+ airline_id: 1
+ flight_number: 203
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
+ dpt_time: 12PM EST
+ arr_time: 3PM CST
+ route: KJFK KAUS
+ - id: flightid_7
+ airline_id: 1
+ flight_number: 204
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
+ dpt_time: 1PM EST
+ arr_time: 4PM CST
+ route: KJFK KAUS
+ - id: flightid_8
+ airline_id: 1
+ flight_number: 205
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
+ dpt_time: 2PM EST
+ arr_time: 5PM CST
+ route: KJFK KAUS
+ - id: flightid_9
+ airline_id: 1
+ flight_number: 206
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
+ dpt_time: 3PM EST
+ arr_time: 6PM CST
+ route: KJFK KAUS
+ - id: flightid_10
+ airline_id: 1
+ flight_number: 207
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
+ dpt_time: 4PM EST
+ arr_time: 7PM CST
+ route: KJFK KAUS
+ - id: flightid_11
+ airline_id: 1
+ flight_number: 208
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
+ dpt_time: 5PM EST
+ arr_time: 8PM CST
+ route: KJFK KAUS
+ - id: flightid_12
+ airline_id: 1
+ flight_number: 209
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
+ dpt_time: 6PM EST
+ arr_time: 9PM CST
+ route: KJFK KAUS
+ - id: flightid_13
+ airline_id: 1
+ flight_number: 210
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
+ dpt_time: 7PM EST
+ arr_time: 10PM CST
+ route: KJFK KAUS
+ - id: flightid_14
+ airline_id: 1
+ flight_number: 211
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
+ dpt_time: 8PM EST
+ arr_time: 11PM CST
+ route: KJFK KAUS
+ - id: flightid_15
+ airline_id: 1
+ flight_number: 212
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
+ dpt_time: 9PM EST
+ arr_time: 12AM CST
+ route: KJFK KAUS
flight_fields:
- id: 1
@@ -232,8 +328,8 @@ pireps:
airline_id: 1
flight_id: flightid_1
aircraft_id: 1
- dpt_airport_id: 1
- arr_airport_id: 2
+ dpt_airport_id: KAUS
+ arr_airport_id: KJFK
flight_time: 21600 # 6 hours
status: -1
notes: just a pilot report
@@ -242,8 +338,8 @@ pireps:
airline_id: 1
flight_id: flightid_2
aircraft_id: 1
- dpt_airport_id: 2
- arr_airport_id: 1
+ dpt_airport_id: KJFK
+ arr_airport_id: KAUS
flight_time: 21600 # 6 hours
status: -1
notes: just a pilot report
diff --git a/resources/views/admin/airports/create.blade.php b/resources/views/admin/airports/create.blade.php
index ef4dec3f..9218675c 100644
--- a/resources/views/admin/airports/create.blade.php
+++ b/resources/views/admin/airports/create.blade.php
@@ -1,22 +1,12 @@
@extends('admin.app')
-
+@section('title', "Add Airport")
@section('content')
- Add Airport
-