middleware('auth'); } public function index($grainID) { $grain = DB::table('grains')->where('id', $grainID)->first(); $grainadditions = Grainbill::where('grain_id', $grainID)->distinct('beer_id')->get(); foreach ($grainadditions as $grains) { $beerName = DB::table('summaries')->where('beer_id', $grains->beer_id)->value('name'); $breweryID = DB::table('summaries')->where('beer_id', $grains->beer_id)->value('brewery_id'); $breweryName = DB::table('breweries')->where('id', $breweryID)->value('name'); $grains['beer'] = $beerName; $grains['breweryID'] = $breweryID; $grains['brewery']=$breweryName; } $grainadditions = $grainadditions->sortBy('brewery'); $data = array('grain'=>$grain, 'grainadditions'=>$grainadditions); return view('grain')->with($data); } }