Browse Source

trying to add dropdowns to edit blades - breweries mkI

master
jk 3 years ago
parent
commit
7750a21133
  1. 5
      app/Http/Controllers/BrewerieController.php
  2. 2
      resources/views/beers/edit.blade.php
  3. 6
      resources/views/breweries/edit.blade.php

5
app/Http/Controllers/BrewerieController.php

@ -45,7 +45,10 @@ class BrewerieController extends Controller
public function edit($id){
$brewery = Brewerie::where('id', (int)$id)->first();
return view('breweries.edit')->with('brewery', $brewery);
$breweries = Brewerie::orderBy('name')->get();
$selected_brewery = $brewery->name;
$data = array('brewery'=>$brewery, 'breweries'=>$breweries, 'selected_brewery'=>$selected_brewery);
return view('breweries.edit')->with($data);
}
public function update(Request $request, $id)

2
resources/views/beers/edit.blade.php

@ -50,7 +50,7 @@
<textarea type="text" class="form-control" name="notes" />{{ $beer->notes }}</textarea>
</div>
<div class="form-group">
<label for="brewery_id">Brewery ID</label>
<label for="brewery_id">Brewery</label>
<select class="form-control" name="brewery_id">
@foreach ($breweries as $brewery)
<option value="{{$brewery->id}}" {{ $selected_brewery == $brewery->id ? 'selected="selected"' : '' }}>{{$brewery->name}}</option>

6
resources/views/breweries/edit.blade.php

@ -19,7 +19,11 @@
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="name" value={{ $brewery->name }} />
<select class="form-control" name="brewery_id">
@foreach ($breweries as $brewer)
<option value="{{$brewer->id}}" {{ $selected_brewery == $brewer->id ? 'selected="selected"' : '' }}>{{$brewer->name}}</option>
@endforeach
</select>
</div>
<div class="form-group">

Loading…
Cancel
Save