Aircraft can be added without subfleet/block subfleet deletion if still in use #128
This commit is contained in:
parent
0e36849f16
commit
cbdce35545
@ -23,6 +23,7 @@ class AircraftController extends BaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the Aircraft.
|
* Display a listing of the Aircraft.
|
||||||
|
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
@ -46,11 +47,12 @@ class AircraftController extends BaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created Aircraft in storage.
|
* Store a newly created Aircraft in storage.
|
||||||
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||||
*/
|
*/
|
||||||
public function store(CreateAircraftRequest $request)
|
public function store(CreateAircraftRequest $request)
|
||||||
{
|
{
|
||||||
$input = $request->all();
|
$input = $request->all();
|
||||||
$aircraft = $this->aircraftRepository->create($input);
|
$this->aircraftRepository->create($input);
|
||||||
|
|
||||||
Flash::success('Aircraft saved successfully.');
|
Flash::success('Aircraft saved successfully.');
|
||||||
return redirect(route('admin.aircraft.index'));
|
return redirect(route('admin.aircraft.index'));
|
||||||
@ -93,6 +95,7 @@ class AircraftController extends BaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified Aircraft in storage.
|
* Update the specified Aircraft in storage.
|
||||||
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||||
*/
|
*/
|
||||||
public function update($id, UpdateAircraftRequest $request)
|
public function update($id, UpdateAircraftRequest $request)
|
||||||
{
|
{
|
||||||
@ -126,5 +129,4 @@ class AircraftController extends BaseController
|
|||||||
Flash::success('Aircraft deleted successfully.');
|
Flash::success('Aircraft deleted successfully.');
|
||||||
return redirect(route('admin.aircraft.index'));
|
return redirect(route('admin.aircraft.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ use App\Models\Subfleet;
|
|||||||
use App\Http\Requests\CreateSubfleetRequest;
|
use App\Http\Requests\CreateSubfleetRequest;
|
||||||
use App\Http\Requests\UpdateSubfleetRequest;
|
use App\Http\Requests\UpdateSubfleetRequest;
|
||||||
|
|
||||||
|
use App\Repositories\AircraftRepository;
|
||||||
use App\Repositories\FareRepository;
|
use App\Repositories\FareRepository;
|
||||||
use App\Repositories\SubfleetRepository;
|
use App\Repositories\SubfleetRepository;
|
||||||
|
|
||||||
@ -23,19 +24,23 @@ use App\Services\FareService;
|
|||||||
class SubfleetController extends BaseController
|
class SubfleetController extends BaseController
|
||||||
{
|
{
|
||||||
/** @var SubfleetRepository */
|
/** @var SubfleetRepository */
|
||||||
private $subfleetRepo, $fareRepo, $fareSvc;
|
private $aircraftRepo, $subfleetRepo, $fareRepo, $fareSvc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SubfleetController constructor.
|
* SubfleetController constructor.
|
||||||
*
|
*
|
||||||
|
* @param AircraftRepository $aircraftRepo
|
||||||
* @param SubfleetRepository $subfleetRepo
|
* @param SubfleetRepository $subfleetRepo
|
||||||
* @param FareRepository $fareRepo
|
* @param FareRepository $fareRepo
|
||||||
|
* @param FareService $fareSvc
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
AircraftRepository $aircraftRepo,
|
||||||
SubfleetRepository $subfleetRepo,
|
SubfleetRepository $subfleetRepo,
|
||||||
FareRepository $fareRepo,
|
FareRepository $fareRepo,
|
||||||
FareService $fareSvc
|
FareService $fareSvc
|
||||||
) {
|
) {
|
||||||
|
$this->aircraftRepo = $aircraftRepo;
|
||||||
$this->subfleetRepo = $subfleetRepo;
|
$this->subfleetRepo = $subfleetRepo;
|
||||||
$this->fareRepo = $fareRepo;
|
$this->fareRepo = $fareRepo;
|
||||||
$this->fareSvc = $fareSvc;
|
$this->fareSvc = $fareSvc;
|
||||||
@ -183,6 +188,14 @@ class SubfleetController extends BaseController
|
|||||||
return redirect(route('admin.subfleets.index'));
|
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);
|
$this->subfleetRepo->delete($id);
|
||||||
|
|
||||||
Flash::success('Subfleet deleted successfully.');
|
Flash::success('Subfleet deleted successfully.');
|
||||||
|
@ -31,6 +31,7 @@ class Aircraft extends BaseModel
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $rules = [
|
public static $rules = [
|
||||||
|
'subfleet_id' => 'required',
|
||||||
'name' => 'required',
|
'name' => 'required',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
18
app/Models/Enums/GenericState.php
Normal file
18
app/Models/Enums/GenericState.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class GenericState
|
||||||
|
* @package App\Models\Enums
|
||||||
|
*/
|
||||||
|
class GenericState extends EnumBase
|
||||||
|
{
|
||||||
|
const INACTIVE = 0;
|
||||||
|
const ACTIVE = 1;
|
||||||
|
|
||||||
|
public static $labels = [
|
||||||
|
GenericState::INACTIVE => 'Inactive',
|
||||||
|
GenericState::ACTIVE => 'Active',
|
||||||
|
];
|
||||||
|
}
|
@ -118,6 +118,7 @@ return [
|
|||||||
'Yaml' => Symfony\Component\Yaml\Yaml::class,
|
'Yaml' => Symfony\Component\Yaml\Yaml::class,
|
||||||
|
|
||||||
# ENUMS
|
# ENUMS
|
||||||
|
'GenericState' => App\Models\Enums\GenericState::class,
|
||||||
'UserState' => App\Models\Enums\UserState::class,
|
'UserState' => App\Models\Enums\UserState::class,
|
||||||
'PirepSource' => App\Models\Enums\PirepSource::class,
|
'PirepSource' => App\Models\Enums\PirepSource::class,
|
||||||
'PirepState' => App\Models\Enums\PirepState::class,
|
'PirepState' => App\Models\Enums\PirepState::class,
|
||||||
|
@ -3,9 +3,15 @@
|
|||||||
@section('content')
|
@section('content')
|
||||||
<div class="card border-blue-bottom">
|
<div class="card border-blue-bottom">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
@if(!filled($subfleets))
|
||||||
|
<p class="text-center">
|
||||||
|
You must add a subfleet before you can add an aircraft!
|
||||||
|
</p>
|
||||||
|
@else
|
||||||
{!! Form::open(['route' => 'admin.aircraft.store']) !!}
|
{!! Form::open(['route' => 'admin.aircraft.store']) !!}
|
||||||
@include('admin.aircraft.fields')
|
@include('admin.aircraft.fields')
|
||||||
{!! Form::close() !!}
|
{!! Form::close() !!}
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
@foreach($aircraft as $ac)
|
@foreach($aircraft as $ac)
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@if($ac->subfleet_id)
|
@if($ac->subfleet_id && $ac->subfleet)
|
||||||
<a href="{!! route('admin.subfleets.edit', [$ac->subfleet_id]) !!}">
|
<a href="{!! route('admin.subfleets.edit', [$ac->subfleet_id]) !!}">
|
||||||
{!! $ac->subfleet->name !!}
|
{!! $ac->subfleet->name !!}
|
||||||
</a>
|
</a>
|
||||||
@ -23,8 +23,8 @@
|
|||||||
<td style="text-align: center;">{!! $ac->icao !!}</td>
|
<td style="text-align: center;">{!! $ac->icao !!}</td>
|
||||||
<td style="text-align: center;">{!! $ac->registration !!}</td>
|
<td style="text-align: center;">{!! $ac->registration !!}</td>
|
||||||
<td style="text-align: center;">
|
<td style="text-align: center;">
|
||||||
@if($ac->active == 1)
|
@if($ac->active == GenericState::ACTIVE)
|
||||||
<span class="label label-success">Active</span>
|
<span class="label label-success">{!! GenericState::label($ac->active); !!}</span>
|
||||||
@else
|
@else
|
||||||
<span class="label label-default">Inactive</span>
|
<span class="label label-default">Inactive</span>
|
||||||
@endif
|
@endif
|
||||||
|
@ -3,9 +3,15 @@
|
|||||||
@section('content')
|
@section('content')
|
||||||
<div class="card border-blue-bottom">
|
<div class="card border-blue-bottom">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
@if(!filled($airlines))
|
||||||
|
<p class="text-center">
|
||||||
|
You must add an airline before you can add a subfleet!
|
||||||
|
</p>
|
||||||
|
@else
|
||||||
{!! Form::open(['route' => 'admin.subfleets.store']) !!}
|
{!! Form::open(['route' => 'admin.subfleets.store']) !!}
|
||||||
@include('admin.subfleets.fields')
|
@include('admin.subfleets.fields')
|
||||||
{!! Form::close() !!}
|
{!! Form::close() !!}
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
Loading…
Reference in New Issue
Block a user