diff --git a/app/Http/Controllers/Admin/AircraftController.php b/app/Http/Controllers/Admin/AircraftController.php index 3fcda55f..5f1c71b6 100644 --- a/app/Http/Controllers/Admin/AircraftController.php +++ b/app/Http/Controllers/Admin/AircraftController.php @@ -16,6 +16,20 @@ class AircraftController extends BaseController /** @var AircraftRepository */ private $aircraftRepository, $fareRepository; + protected function getAvailFares($all_fares, $attached_fares) + { + $retval = []; + $avail_fares = $all_fares->except($attached_fares->modelKeys()); + foreach ($avail_fares as $fare) { + $retval[$fare->id] = $fare->name. + ' (price: '.$fare->price. + ', cost: '.$fare->cost. + ', capacity: '.$fare->capacity.')'; + } + + return $retval; + } + public function __construct(AircraftRepository $aircraftRepo, FareRepository $fareRepo) { $this->fareRepository = $fareRepo; @@ -69,7 +83,7 @@ class AircraftController extends BaseController $attached_fares = $aircraft->fares; $all_fares = $this->fareRepository->all(); - $avail_fares = $all_fares->except($attached_fares->modelKeys()); + $avail_fares = $this->getAvailFares($all_fares, $attached_fares); return view('admin.aircraft.show') ->with('aircraft', $aircraft) @@ -132,9 +146,10 @@ class AircraftController extends BaseController protected function return_fares_view($aircraft) { + $aircraft->refresh(); $attached_fares = $aircraft->fares; $all_fares = $this->fareRepository->all(); - $avail_fares = $all_fares->except($attached_fares->modelKeys()); + $avail_fares = $this->getAvailFares($all_fares, $attached_fares); return view('admin.aircraft.fares') ->with('aircraft', $aircraft) @@ -151,11 +166,15 @@ class AircraftController extends BaseController return view('admin.aircraft.fares')->with('fares', []); } + $fare_svc = app('App\Services\FareService'); + // associate or dissociate the fare with this aircraft if ($request->isMethod('post') || $request->isMethod('put')) { - // add + $fare = $this->fareRepository->findWithoutFail($request->fare_id); + $fare_svc->setForAircraft($aircraft, $fare); } elseif ($request->isMethod('delete')) { - print_r($request->request); + $fare = $this->fareRepository->findWithoutFail($request->fare_id); + $fare_svc->delFromAircraft($aircraft, $fare); } return $this->return_fares_view($aircraft); diff --git a/resources/views/admin/aircraft/fares.blade.php b/resources/views/admin/aircraft/fares.blade.php index 4fb75695..f03bf75f 100644 --- a/resources/views/admin/aircraft/fares.blade.php +++ b/resources/views/admin/aircraft/fares.blade.php @@ -56,5 +56,25 @@
- {!! $avail_fares !!} +
+
+
+ {!! Form::open(['url' => '/admin/aircraft/'.$aircraft->id.'/fares', + 'method' => 'post', + 'class' => 'rm_fare form-inline' + ]) + !!} + {!! Form::select('fare_id', $avail_fares, null, [ + 'placeholder' => 'Select Fare', + 'class' => 'ac-fare-dropdown form-control input-lg', + + ]) + !!} + {!! Form::button(' add', + ['type' => 'submit', + 'class' => 'btn btn-success btn-s']) !!} + {!! Form::close() !!} +
+
+
diff --git a/resources/views/admin/aircraft/show.blade.php b/resources/views/admin/aircraft/show.blade.php index fd1d1a23..855894b9 100644 --- a/resources/views/admin/aircraft/show.blade.php +++ b/resources/views/admin/aircraft/show.blade.php @@ -24,8 +24,8 @@ @section('scripts')