Aircraft can be added without subfleet/block subfleet deletion if still in use #128
This commit is contained in:
@@ -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.');
|
||||
|
||||
Reference in New Issue
Block a user