My beer compendium
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.3 KiB

3 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Brewerie;
  5. use App\Models\Summarie;
  6. use App\Models\Grainbill;
  7. use App\Models\Hopaddition;
  8. use App\Models\Adjunctaddition;
  9. use App\Models\Adjunct;
  10. use App\Models\Hop;
  11. use App\Models\Grain;
  12. use App\Models\Fermentation;
  13. use App\Models\Yeast;
  14. use App\Models\Mashe;
  15. use Illuminate\Support\Facades\DB;
  16. class BeerController extends Controller
  17. {
  18. public function __construct()
  19. {
  20. $this->middleware('auth');
  21. }
  22. public function index($beerID)
  23. {
  24. $beer = DB::table('summaries')->where('beer_id', $beerID)->first();
  25. $breweries = Brewerie::where('id', $beer->brewery_id)->get();
  26. $grainbills = Grainbill::where('beer_id', $beerID)->get();
  27. foreach($grainbills as $grain)
  28. {
  29. $grainname = DB::table('grains')->where('id', $grain->grain_id)->first();
  30. $grain['grain_name'] = $grainname->name;
  31. };
  32. $mashsteps = Mashe::where('beer_id', $beerID)->get();
  33. $hopadditions = Hopaddition::where('beer_id', $beerID)->get();
  34. foreach($hopadditions as $hop)
  35. {
  36. $hopname = DB::table('hops')->where('id', $hop->hop_id)->first();
  37. $hop['hop_name'] = $hopname->name;
  38. };
  39. $yeastadditions = Fermentation::where('beer_id', $beerID)->get();
  40. foreach($yeastadditions as $yeast)
  41. {
  42. $yeastname = DB::table('yeasts')->where('id', $yeast->yeast_id)->first();
  43. $yeast['yeast_name'] = $yeastname->name;
  44. if($yeast->alternative) {
  45. $altname = DB::table('yeasts')->where('id', $yeast->alternative)->value('name');
  46. $yeast['altname'] = $altname;
  47. }
  48. };
  49. $adjunctadditions = Adjunctaddition::where('beer_id', $beerID)->get();
  50. foreach($adjunctadditions as $adjunct)
  51. {
  52. $adjunctname = DB::table('adjuncts')->where('id', $adjunct->adjunct_id)->first();
  53. $adjunct['adjunct_name'] = $adjunctname->name;
  54. };
  55. $data = array('breweries'=>$breweries, 'beer'=>$beer, 'grainbills'=>$grainbills, 'mashsteps'=>$mashsteps, 'hopadditions'=>$hopadditions, 'adjunctadditions'=>$adjunctadditions, 'yeastadditions'=>$yeastadditions);
  56. return view('beer')->with($data);
  57. }
  58. }