Browse Source

trying to add dropdowns to edit blades - hopadditions mkI

master
jk 3 years ago
parent
commit
135bf67a6c
  1. 5
      app/Http/Controllers/HopAdditionController.php
  2. 16
      resources/views/hopadditions/edit.blade.php

5
app/Http/Controllers/HopAdditionController.php

@ -49,6 +49,11 @@ class HopAdditionController extends Controller
} }
public function edit($id){ public function edit($id){
$hopaddition = Hopaddition::where('id', (int)$id)->first(); $hopaddition = Hopaddition::where('id', (int)$id)->first();
$beers = Summarie::orderBy('name')->get();
$selected_beer = $hopaddition->beer_id;
$hops = Hop::orderBy('name')->get();
$selected_hop = $hopaddition->hop_id;
$data = array('hopaddition'=>$hopaddition, 'beers'=>$beers, 'hops'=>$hops, 'selected_beer'=>$selected_beer, 'selected_hop'=>$selected_hop);
return view('hopadditions.edit')->with('hopaddition', $hopaddition); return view('hopadditions.edit')->with('hopaddition', $hopaddition);
} }

16
resources/views/hopadditions/edit.blade.php

@ -17,12 +17,20 @@
@method('PATCH') @method('PATCH')
@csrf @csrf
<div class="form-group"> <div class="form-group">
<label for="beer_id">Beer ID</label>
<input type="text" class="form-control" name="beer_id" value="{{$hopaddition->beer_id}}" />
<label for="beer_id">Beer</label>
<select class="form-control" name="beer_id">
@foreach ($beers as $beer)
<option value="{{$beer->beer_id}}" {{ $selected_beer == $beer->beer_id ? 'selected="selected"' : '' }}>{{$beer->name}}</option>
@endforeach
</select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="hop_id">Hop ID</label>
<input type="text" class="form-control" name="hop_id" value="{{$hopaddition->hop_id}}" />
<label for="hop_id">Hop</label>
<select class="form-control" name="hop_id">
@foreach ($hops as $hop)
<option value="{{$hop->id}}" {{ $selected_hop == $hop->id ? 'selected="selected"' : '' }}>{{$hop->name}}</option>
@endforeach
</select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="amount">Amount</label> <label for="amount">Amount</label>

Loading…
Cancel
Save