diff --git a/app/Http/Controllers/Admin/AircraftController.php b/app/Http/Controllers/Admin/AircraftController.php index c8f8a8985..509312b71 100644 --- a/app/Http/Controllers/Admin/AircraftController.php +++ b/app/Http/Controllers/Admin/AircraftController.php @@ -43,26 +43,38 @@ public function __construct( /** * Display a listing of the Aircraft. - * @throws \Prettus\Repository\Exceptions\RepositoryException + * @param Request $request + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function index(Request $request) { - $this->aircraftRepo->pushCriteria(new RequestCriteria($request)); - $aircraft = $this->aircraftRepo->orderBy('registration', 'asc')->all(); + // If subfleet ID is passed part of the query string, then only + // show the aircraft that are in that subfleet + $w = []; + if($request->filled('subfleet')) { + $w['subfleet_id'] = $request->input('subfleet'); + } + + $aircraft = $this->aircraftRepo->whereOrder($w, 'registration', 'asc'); + $aircraft = $aircraft->all(); return view('admin.aircraft.index', [ - 'aircraft' => $aircraft + 'aircraft' => $aircraft, + 'subfleet_id' => $request->input('subfleet'), ]); } /** * Show the form for creating a new Aircraft. + * @param Request $request + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function create() + public function create(Request $request) { return view('admin.aircraft.create', [ 'subfleets' => Subfleet::all()->pluck('name', 'id'), 'statuses' => AircraftStatus::select(true), + 'subfleet_id' => $request->query('subfleet') ]); } diff --git a/resources/views/admin/aircraft/fields.blade.php b/resources/views/admin/aircraft/fields.blade.php index 28e33c057..639f18b0c 100644 --- a/resources/views/admin/aircraft/fields.blade.php +++ b/resources/views/admin/aircraft/fields.blade.php @@ -1,7 +1,11 @@
{{ $errors->first('subfleet_id') }}