diff --git a/app/Http/Controllers/Admin/AircraftController.php b/app/Http/Controllers/Admin/AircraftController.php index 3fc128e5..3fcda55f 100644 --- a/app/Http/Controllers/Admin/AircraftController.php +++ b/app/Http/Controllers/Admin/AircraftController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreateAircraftRequest; use App\Http\Requests\UpdateAircraftRequest; use App\Repositories\AircraftRepository; +use App\Repositories\FareRepository; use Illuminate\Http\Request; use Flash; use Prettus\Repository\Criteria\RequestCriteria; @@ -13,10 +14,11 @@ use Response; class AircraftController extends BaseController { /** @var AircraftRepository */ - private $aircraftRepository; + private $aircraftRepository, $fareRepository; - public function __construct(AircraftRepository $aircraftRepo) + public function __construct(AircraftRepository $aircraftRepo, FareRepository $fareRepo) { + $this->fareRepository = $fareRepo; $this->aircraftRepository = $aircraftRepo; } @@ -65,7 +67,14 @@ class AircraftController extends BaseController return redirect(route('admin.aircraft.index')); } - return view('admin.aircraft.show')->with('aircraft', $aircraft); + $attached_fares = $aircraft->fares; + $all_fares = $this->fareRepository->all(); + $avail_fares = $all_fares->except($attached_fares->modelKeys()); + + return view('admin.aircraft.show') + ->with('aircraft', $aircraft) + ->with('attached_fares', $attached_fares) + ->with('avail_fares', $avail_fares); } /** @@ -121,6 +130,18 @@ class AircraftController extends BaseController return redirect(route('admin.aircraft.index')); } + protected function return_fares_view($aircraft) + { + $attached_fares = $aircraft->fares; + $all_fares = $this->fareRepository->all(); + $avail_fares = $all_fares->except($attached_fares->modelKeys()); + + return view('admin.aircraft.fares') + ->with('aircraft', $aircraft) + ->with('attached_fares', $attached_fares) + ->with('avail_fares', $avail_fares); + } + public function fares(Request $request) { $id = $request->id; @@ -132,12 +153,11 @@ class AircraftController extends BaseController // associate or dissociate the fare with this aircraft if ($request->isMethod('post') || $request->isMethod('put')) { - + // add } elseif ($request->isMethod('delete')) { - + print_r($request->request); } - return view('admin.aircraft.fares') - ->with('fare', $aircraft->fares); + return $this->return_fares_view($aircraft); } } diff --git a/config/app.php b/config/app.php index 2d24f529..a026b01b 100755 --- a/config/app.php +++ b/config/app.php @@ -143,7 +143,8 @@ return [ 'View' => Illuminate\Support\Facades\View::class, 'Form' => Collective\Html\FormFacade::class, 'Html' => Collective\Html\HtmlFacade::class, - 'Flash' => Laracasts\Flash\Flash::class + 'Flash' => Laracasts\Flash\Flash::class, + 'Yaml' => Symfony\Component\Yaml\Yaml::class, ], ]; diff --git a/resources/views/admin/aircraft/fares.blade.php b/resources/views/admin/aircraft/fares.blade.php index 6e4bc36c..4fb75695 100644 --- a/resources/views/admin/aircraft/fares.blade.php +++ b/resources/views/admin/aircraft/fares.blade.php @@ -1,22 +1,60 @@ - - - - - - -@foreach($fares as $fare) - - - - -@endforeach - -
Action
{!! $ac->icao !!} - {!! Form::open(['route' => ['admin.aircraft.destroy', $ac->id], 'method' => 'delete']) !!} -
- - - {!! Form::button('', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure?')"]) !!} -
- {!! Form::close() !!} -
+
+ + + + + + + + + + + + + @foreach($attached_fares as $atf) + + + + + + + + + @endforeach + +
+ name + + code + + capacity + + price + + cost +
{!! $atf->name !!}{!! $atf->code !!}{!! $atf->capacity !!}{!! $atf->price !!}{!! $atf->cost !!} +
+ {!! Form::open(['url' => '/admin/aircraft/'.$aircraft->id.'/fares', 'method' => 'delete', 'class' => 'rm_fare']) !!} + {!! Form::hidden('fare_id', $atf->id) !!} + {!! Form::button('', + ['type' => 'submit', + 'class' => 'btn btn-danger btn-s']) !!} + {!! Form::close() !!} +
+
+
+ {!! $avail_fares !!} +
diff --git a/resources/views/admin/aircraft/fields.blade.php b/resources/views/admin/aircraft/fields.blade.php index c3ebd5d6..411dcebe 100644 --- a/resources/views/admin/aircraft/fields.blade.php +++ b/resources/views/admin/aircraft/fields.blade.php @@ -24,11 +24,13 @@
- {!! Form::label('active', 'Active:') !!} - +
+ +
@@ -36,3 +38,8 @@ {!! Form::submit('Save', ['class' => 'btn btn-primary']) !!} Cancel + diff --git a/resources/views/admin/aircraft/show.blade.php b/resources/views/admin/aircraft/show.blade.php index 1e3d82e9..fd1d1a23 100644 --- a/resources/views/admin/aircraft/show.blade.php +++ b/resources/views/admin/aircraft/show.blade.php @@ -1,19 +1,34 @@ @extends('admin.app') @section('content') -
-

- Aircraft -

-
-
-
-
-
- @include('admin.aircraft.show_fields') - Back +

{!! $aircraft->name !!}

+
+
+ @include('admin.aircraft.show_fields') +
+
+
+
+
+
+

fares

+
+ @include('admin.aircraft.fares') +
+
+@endsection +@section('scripts') + @endsection diff --git a/resources/views/admin/aircraft/show_fields.blade.php b/resources/views/admin/aircraft/show_fields.blade.php index 7d20053a..36911d18 100644 --- a/resources/views/admin/aircraft/show_fields.blade.php +++ b/resources/views/admin/aircraft/show_fields.blade.php @@ -1,36 +1,43 @@
- {!! Form::label('icao', 'ICAO:') !!} -

{!! $aircraft->icao !!}

+
+
+ {{----}} +

{!! Form::label('icao', 'ICAO:') !!}

+
+

{!! $aircraft->icao !!}

+
- {!! Form::label('name', 'Name:') !!} -

{!! $aircraft->name !!}

+
+
+ {{----}} +

{!! Form::label('name', 'Name:') !!}

+
+

{!! $aircraft->name !!}

+
- {!! Form::label('registration', 'Registration:') !!} -

{!! $aircraft->registration !!}

+
+
+ {{----}} +

{!! Form::label('registration', 'Registration:') !!}

+
+

{!! $aircraft->registration !!}

+
- {!! Form::label('active', 'Active:') !!} -

{!! $aircraft->active !!}

+
+
+ {{----}} +

{!! Form::label('active', 'Active:') !!}

+
+

@if ($aircraft->active == '1') yes @else no @endif

+
- - -
- {!! Form::label('created_at', 'Created At:') !!} -

{!! $aircraft->created_at !!}

-
- - -
- {!! Form::label('updated_at', 'Updated At:') !!} -

{!! $aircraft->updated_at !!}

-
- diff --git a/resources/views/admin/app.blade.php b/resources/views/admin/app.blade.php index dc387efb..de525917 100644 --- a/resources/views/admin/app.blade.php +++ b/resources/views/admin/app.blade.php @@ -174,10 +174,11 @@ @endif - + +