cleanup aircraft table/repo

This commit is contained in:
Nabeel Shahzad
2017-06-24 14:00:56 -05:00
parent fe1100e57f
commit 5dce55b4f3
11 changed files with 23 additions and 61 deletions
+2 -1
View File
@@ -18,10 +18,11 @@ install: db
echo "" echo ""
clean: clean:
@php artisan cache:clear
@php artisan optimize @php artisan optimize
@php artisan route:clear @php artisan route:clear
@php artisan config:clear @php artisan config:clear
@rm -f database/testing.sqlite @rm -f database/*.sqlite
reset: clean reset: clean
@sqlite3 database/testing.sqlite "" @sqlite3 database/testing.sqlite ""
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
use App\Models\Subfleet; use App\Models\Subfleet;
use App\Http\Requests\CreateAircraftRequest; use App\Http\Requests\CreateAircraftRequest;
use App\Http\Requests\UpdateAircraftRequest; use App\Http\Requests\UpdateAircraftRequest;
use App\Repositories\AircraftRepository;
use App\Repositories\SubfleetRepository; use App\Repositories\SubfleetRepository;
use App\Repositories\FareRepository; use App\Repositories\FareRepository;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@@ -18,7 +19,7 @@ class AircraftController extends BaseController
private $aircraftRepository, $fareRepository; private $aircraftRepository, $fareRepository;
public function __construct( public function __construct(
SubfleetRepository $aircraftRepo, AircraftRepository $aircraftRepo,
FareRepository $fareRepo FareRepository $fareRepo
) { ) {
$this->fareRepository = $fareRepo; $this->fareRepository = $fareRepo;
@@ -106,8 +107,8 @@ class AircraftController extends BaseController
return redirect(route('admin.aircraft.index')); return redirect(route('admin.aircraft.index'));
} }
// print_r($request->toArray());
$aircraft = $this->aircraftRepository->update($request->all(), $id); $aircraft = $this->aircraftRepository->update($request->all(), $id);
Flash::success('Aircraft updated successfully.'); Flash::success('Aircraft updated successfully.');
return redirect(route('admin.aircraft.index')); return redirect(route('admin.aircraft.index'));
} }
+6 -3
View File
@@ -19,7 +19,7 @@ class Aircraft extends Model
public $fillable public $fillable
= [ = [
'subfleet_id', 'subfleet_id',
'icao', 'airport_id',
'name', 'name',
'registration', 'registration',
'tail_number', 'tail_number',
@@ -33,7 +33,7 @@ class Aircraft extends Model
*/ */
protected $casts protected $casts
= [ = [
'icao' => 'string', 'subfleet_id' => 'string',
'name' => 'string', 'name' => 'string',
'registration' => 'string', 'registration' => 'string',
'active' => 'boolean', 'active' => 'boolean',
@@ -46,7 +46,6 @@ class Aircraft extends Model
*/ */
public static $rules public static $rules
= [ = [
'icao' => 'required|max:5',
'name' => 'required', 'name' => 'required',
'active' => '', 'active' => '',
]; ];
@@ -54,6 +53,10 @@ class Aircraft extends Model
/** /**
* foreign keys * foreign keys
*/ */
public function airport()
{
return $this->belongsTo('App\Models\Airport', 'airport_id');
}
public function subfleet() public function subfleet()
{ {
@@ -1,25 +0,0 @@
<?php
namespace App\Repositories;
use App\Models\AircraftClass;
class AircraftClassRepository extends BaseRepository
{
/**
* @var array
*/
protected $fieldSearchable = [
'class',
'name',
'notes'
];
/**
* Configure the Model
**/
public function model()
{
return AircraftClass::class;
}
}
-7
View File
@@ -11,9 +11,7 @@ class AircraftRepository extends BaseRepository
*/ */
protected $fieldSearchable protected $fieldSearchable
= [ = [
'icao',
'name', 'name',
'full_name',
'registration', 'registration',
'active', 'active',
]; ];
@@ -25,9 +23,4 @@ class AircraftRepository extends BaseRepository
{ {
return Aircraft::class; return Aircraft::class;
} }
public function findByICAO($icao)
{
return $this->findByField('icao', $icao)->first();
}
} }
@@ -10,15 +10,11 @@ class CreateAircraftsTable extends Migration
Schema::create('aircraft', function (Blueprint $table) { Schema::create('aircraft', function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->integer('subfleet_id')->unsigned(); $table->integer('subfleet_id')->unsigned();
$table->integer('airport_id')->unsigned()->nullable();
$table->string('hex_code')->nullable(); $table->string('hex_code')->nullable();
$table->string('icao');
$table->string('name'); $table->string('name');
$table->string('registration')->nullable(); $table->string('registration')->nullable();
$table->string('tail_number')->nullable(); $table->string('tail_number')->nullable();
$table->double('cargo_capacity', 19, 2)->nullable();
$table->double('fuel_capacity', 19, 2)->nullable();
$table->double('gross_weight', 19, 2)->nullable();
$table->tinyInteger('fuel_type')->unsigned()->nullable();
$table->boolean('active')->default(true); $table->boolean('active')->default(true);
$table->timestamps(); $table->timestamps();
@@ -18,6 +18,10 @@ class CreateSubfleetsTable extends Migration
$table->integer('airline_id')->unsigned()->nullable(); $table->integer('airline_id')->unsigned()->nullable();
$table->string('name'); $table->string('name');
$table->text('type'); $table->text('type');
$table->double('cargo_capacity', 19, 2)->nullable();
$table->double('fuel_capacity', 19, 2)->nullable();
$table->double('gross_weight', 19, 2)->nullable();
$table->tinyInteger('fuel_type')->unsigned()->nullable();
$table->timestamps(); $table->timestamps();
$table->softDeletes(); $table->softDeletes();
}); });
-2
View File
@@ -74,13 +74,11 @@ airports:
aircraft: aircraft:
- id: 1 - id: 1
subfleet_id: 1 subfleet_id: 1
icao: B744
name: Boeing 747-400 name: Boeing 747-400
registration: NC17 registration: NC17
tail_number: 17 tail_number: 17
- id: 2 - id: 2
subfleet_id: 2 subfleet_id: 2
icao: B772
name: Boeing 777-200 name: Boeing 777-200
registration: NC20 registration: NC20
tail_number: 20 tail_number: 20
@@ -1,9 +1,3 @@
<!-- ICAO Field -->
<div class="form-group col-sm-6">
{!! Form::label('icao', 'ICAO:') !!} (<a class="small" href="https://www.icao.int/publications/DOC8643/Pages/Search.aspx" target="_blank">find</a>)
{!! Form::text('icao', null, ['class' => 'form-control']) !!}
</div>
<!-- Name Field --> <!-- Name Field -->
<div class="form-group col-sm-6"> <div class="form-group col-sm-6">
{!! Form::label('name', 'Name:') !!} {!! Form::label('name', 'Name:') !!}
@@ -2,13 +2,12 @@
<div class="form-group col-sm-6"> <div class="form-group col-sm-6">
<div class="box box-solid"> <div class="box box-solid">
<div class="box-header with-border"> <div class="box-header with-border">
{{--<i class="fa fa-text-width"></i>--}} <h3 class="box-title">{!! Form::label('airport_id', 'Location') !!}</h3>
<h3 class="box-title">{!! Form::label('icao', 'ICAO') !!}</h3>
</div> </div>
<div class="box-body"> <div class="box-body">
<p class="lead">{!! $aircraft->icao !!} <p class="lead">
@if($aircraft->subfleet) @if($aircraft->airport)
/{!! $aircraft->subfleet->name !!}</p> {!! $aircraft->airport->icao !!}</p>
@endif @endif
</div> </div>
</div> </div>
@@ -1,8 +1,7 @@
<table class="table table-responsive" id="aircrafts-table"> <table class="table table-responsive" id="aircrafts-table">
<thead> <thead>
<th>ICAO</th>
<th>Name</th>
<th>Subfleet</th> <th>Subfleet</th>
<th>Name</th>
<th>Registration</th> <th>Registration</th>
<th style="text-align: center;">Active</th> <th style="text-align: center;">Active</th>
<th style="text-align: center;">Actions</th> <th style="text-align: center;">Actions</th>
@@ -10,15 +9,14 @@
<tbody> <tbody>
@foreach($aircraft as $ac) @foreach($aircraft as $ac)
<tr> <tr>
<td><a href="{!! route('admin.aircraft.show', [$ac->id]) !!}">{!! $ac->icao !!}</a></td>
<td>{!! $ac->name !!}</td>
<td> <td>
@if($ac->subfleet) @if($ac->subfleet_id)
{!! $ac->subfleet->name !!} {!! $ac->subfleet->name !!}
@else @else
- -
@endif @endif
</td> </td>
<td><a href="{!! route('admin.aircraft.show', [$ac->id]) !!}">{!! $ac->name !!}</a></td>
<td>{!! $ac->registration !!}</td> <td>{!! $ac->registration !!}</td>
<td style="text-align: center;"> <td style="text-align: center;">
<i class="fa fa-{{$ac->active == 1?"check":""}}-square-o" aria-hidden="true" <i class="fa fa-{{$ac->active == 1?"check":""}}-square-o" aria-hidden="true"