diff --git a/app/Http/Controllers/Admin/AircraftController.php b/app/Http/Controllers/Admin/AircraftController.php index 2bc274f2..682ce81b 100644 --- a/app/Http/Controllers/Admin/AircraftController.php +++ b/app/Http/Controllers/Admin/AircraftController.php @@ -23,6 +23,7 @@ class AircraftController extends BaseController /** * Display a listing of the Aircraft. + * @throws \Prettus\Repository\Exceptions\RepositoryException */ public function index(Request $request) { @@ -46,11 +47,12 @@ class AircraftController extends BaseController /** * Store a newly created Aircraft in storage. + * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function store(CreateAircraftRequest $request) { $input = $request->all(); - $aircraft = $this->aircraftRepository->create($input); + $this->aircraftRepository->create($input); Flash::success('Aircraft saved successfully.'); return redirect(route('admin.aircraft.index')); @@ -93,6 +95,7 @@ class AircraftController extends BaseController /** * Update the specified Aircraft in storage. + * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function update($id, UpdateAircraftRequest $request) { @@ -126,5 +129,4 @@ class AircraftController extends BaseController Flash::success('Aircraft deleted successfully.'); return redirect(route('admin.aircraft.index')); } - } diff --git a/app/Http/Controllers/Admin/SubfleetController.php b/app/Http/Controllers/Admin/SubfleetController.php index 310bd59f..ad422de4 100644 --- a/app/Http/Controllers/Admin/SubfleetController.php +++ b/app/Http/Controllers/Admin/SubfleetController.php @@ -15,6 +15,7 @@ use App\Models\Subfleet; use App\Http\Requests\CreateSubfleetRequest; use App\Http\Requests\UpdateSubfleetRequest; +use App\Repositories\AircraftRepository; use App\Repositories\FareRepository; use App\Repositories\SubfleetRepository; @@ -23,19 +24,23 @@ use App\Services\FareService; class SubfleetController extends BaseController { /** @var SubfleetRepository */ - private $subfleetRepo, $fareRepo, $fareSvc; + private $aircraftRepo, $subfleetRepo, $fareRepo, $fareSvc; /** * SubfleetController constructor. * + * @param AircraftRepository $aircraftRepo * @param SubfleetRepository $subfleetRepo - * @param FareRepository $fareRepo + * @param FareRepository $fareRepo + * @param FareService $fareSvc */ public function __construct( + AircraftRepository $aircraftRepo, SubfleetRepository $subfleetRepo, FareRepository $fareRepo, FareService $fareSvc ) { + $this->aircraftRepo = $aircraftRepo; $this->subfleetRepo = $subfleetRepo; $this->fareRepo = $fareRepo; $this->fareSvc = $fareSvc; @@ -183,6 +188,14 @@ class SubfleetController extends BaseController return redirect(route('admin.subfleets.index')); } + # Make sure no aircraft are assigned to this subfleet + # before trying to delete it, or else things might go boom + $aircraft = $this->aircraftRepo->findWhere(['subfleet_id' => $id], ['id']); + if($aircraft->count() > 0) { + Flash::error('There are aircraft still assigned to this subfleet, you can\'t delete it!')->important(); + return redirect(route('admin.subfleets.index')); + } + $this->subfleetRepo->delete($id); Flash::success('Subfleet deleted successfully.'); diff --git a/app/Models/Aircraft.php b/app/Models/Aircraft.php index 1e227205..2b2a1b0c 100644 --- a/app/Models/Aircraft.php +++ b/app/Models/Aircraft.php @@ -31,6 +31,7 @@ class Aircraft extends BaseModel * @var array */ public static $rules = [ + 'subfleet_id' => 'required', 'name' => 'required', ]; diff --git a/app/Models/Enums/GenericState.php b/app/Models/Enums/GenericState.php new file mode 100644 index 00000000..fe7475c0 --- /dev/null +++ b/app/Models/Enums/GenericState.php @@ -0,0 +1,18 @@ + 'Inactive', + GenericState::ACTIVE => 'Active', + ]; +} diff --git a/config/app.php b/config/app.php index bbdd0f8e..07f27fc5 100755 --- a/config/app.php +++ b/config/app.php @@ -118,6 +118,7 @@ return [ 'Yaml' => Symfony\Component\Yaml\Yaml::class, # ENUMS + 'GenericState' => App\Models\Enums\GenericState::class, 'UserState' => App\Models\Enums\UserState::class, 'PirepSource' => App\Models\Enums\PirepSource::class, 'PirepState' => App\Models\Enums\PirepState::class, diff --git a/resources/views/admin/aircraft/create.blade.php b/resources/views/admin/aircraft/create.blade.php index 187987a8..27e8680b 100644 --- a/resources/views/admin/aircraft/create.blade.php +++ b/resources/views/admin/aircraft/create.blade.php @@ -3,9 +3,15 @@ @section('content')
- {!! Form::open(['route' => 'admin.aircraft.store']) !!} - @include('admin.aircraft.fields') - {!! Form::close() !!} + @if(!filled($subfleets)) +

+ You must add a subfleet before you can add an aircraft! +

+ @else + {!! Form::open(['route' => 'admin.aircraft.store']) !!} + @include('admin.aircraft.fields') + {!! Form::close() !!} + @endif
@endsection diff --git a/resources/views/admin/aircraft/table.blade.php b/resources/views/admin/aircraft/table.blade.php index 1ca9b26d..7904aaea 100644 --- a/resources/views/admin/aircraft/table.blade.php +++ b/resources/views/admin/aircraft/table.blade.php @@ -11,7 +11,7 @@ @foreach($aircraft as $ac) - @if($ac->subfleet_id) + @if($ac->subfleet_id && $ac->subfleet) {!! $ac->subfleet->name !!} @@ -23,8 +23,8 @@ {!! $ac->icao !!} {!! $ac->registration !!} - @if($ac->active == 1) - Active + @if($ac->active == GenericState::ACTIVE) + {!! GenericState::label($ac->active); !!} @else Inactive @endif diff --git a/resources/views/admin/subfleets/create.blade.php b/resources/views/admin/subfleets/create.blade.php index 7ad8887d..f514ce7c 100644 --- a/resources/views/admin/subfleets/create.blade.php +++ b/resources/views/admin/subfleets/create.blade.php @@ -3,9 +3,15 @@ @section('content')
- {!! Form::open(['route' => 'admin.subfleets.store']) !!} - @include('admin.subfleets.fields') - {!! Form::close() !!} + @if(!filled($airlines)) +

+ You must add an airline before you can add a subfleet! +

+ @else + {!! Form::open(['route' => 'admin.subfleets.store']) !!} + @include('admin.subfleets.fields') + {!! Form::close() !!} + @endif
@endsection