Skip to content

Commit

Permalink
Rebased and fixed issue nabeelio#1275
Browse files Browse the repository at this point in the history
  • Loading branch information
YashGovekar committed Oct 26, 2022
1 parent b4311b8 commit be0cbb1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion app/Http/Controllers/Admin/RankController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Http\Requests\UpdateRankRequest;
use App\Repositories\RankRepository;
use App\Repositories\SubfleetRepository;
use App\Repositories\UserRepository;
use App\Services\FleetService;
use Cache;
use Illuminate\Http\Request;
Expand All @@ -18,22 +19,26 @@ class RankController extends Controller
private FleetService $fleetSvc;
private RankRepository $rankRepository;
private SubfleetRepository $subfleetRepo;
private UserRepository $userRepo;

/**
* RankController constructor.
*
* @param FleetService $fleetSvc
* @param RankRepository $rankingRepo
* @param SubfleetRepository $subfleetRepo
* @param UserRepository $userRepo
*/
public function __construct(
FleetService $fleetSvc,
RankRepository $rankingRepo,
SubfleetRepository $subfleetRepo
SubfleetRepository $subfleetRepo,
UserRepository $userRepo
) {
$this->fleetSvc = $fleetSvc;
$this->rankRepository = $rankingRepo;
$this->subfleetRepo = $subfleetRepo;
$this->userRepo = $userRepo;
}

/**
Expand Down Expand Up @@ -190,6 +195,19 @@ public function update($id, UpdateRankRequest $request)
*/
public function destroy($id)
{
$rank_in_use = $this->userRepo->findWhere(['rank_id' => $id])->count();
if ($rank_in_use > 0) {
Flash::error('Rank cannot be deleted since it\'s already assigned to one or more pilots!');

return redirect(route('admin.ranks.index'));
}

if ($this->rankRepository->count() === 1) {
Flash::error('Rank cannot be deleted since it\'s the only remaining rank in your database!');

return redirect(route('admin.ranks.index'));
}

$rank = $this->rankRepository->findWithoutFail($id);

if (empty($rank)) {
Expand Down

0 comments on commit be0cbb1

Please sign in to comment.