Browse Source

trying to add dropdowns to edit blades - grainbills mkI

master
jk 3 years ago
parent
commit
2eb39f9415
  1. 7
      app/Http/Controllers/GrainbillController.php
  2. 16
      resources/views/grainbills/edit.blade.php

7
app/Http/Controllers/GrainbillController.php

@ -51,7 +51,12 @@ class GrainbillController extends Controller
} }
public function edit($id){ public function edit($id){
$grainbill = Grainbill::where('id', (int)$id)->first(); $grainbill = Grainbill::where('id', (int)$id)->first();
return view('grainbills.edit')->with('grainbill', $grainbill);
$beers = Summarie::orderBy('name')->get();
$selected_beer = $grainbill->beer_id;
$grains = Grain::orderBy('name')->get();
$selected_grain = $grainbill->grain_id;
$data = array('grainbill'=>$grainbill, 'beers'=>$beers, 'grains'=>$grains, 'selected_beer'=>$selected_beer, 'selected_grain'=>$selected_grain);
return view('grainbills.edit')->with($data);
} }
public function update(Request $request, $id){ public function update(Request $request, $id){

16
resources/views/grainbills/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="{{$grainbill->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="grain_id">Grain ID</label>
<input type="text" class="form-control" name="grain_id" value="{{$grainbill->grain_id}}" />
<label for="grain_id">Grain</label>
<select class="form-control" name="grain_id">
@foreach ($grains as $grain)
<option value="{{$grain->id}}" {{ $selected_grain == $grain->id ? 'selected="selected"' : '' }}>{{$grain->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