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

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Brewerie;
use App\Models\Summarie;
use App\Models\Grainbill;
use App\Models\Hopaddition;
use App\Models\Adjunctaddition;
use App\Models\Adjunct;
use App\Models\Hop;
use App\Models\Grain;
use App\Models\Fermentation;
use App\Models\Yeast;
use App\Models\Mashe;
use Illuminate\Support\Facades\DB;
class BeerController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index($beerID)
{
$beer = DB::table('summaries')->where('beer_id', $beerID)->first();
$breweries = Brewerie::where('id', $beer->brewery_id)->get();
$grainbills = Grainbill::where('beer_id', $beerID)->get();
foreach($grainbills as $grain)
{
$grainname = DB::table('grains')->where('id', $grain->grain_id)->first();
$grain['grain_name'] = $grainname->name;
};
$mashsteps = Mashe::where('beer_id', $beerID)->get();
$hopadditions = Hopaddition::where('beer_id', $beerID)->get();
foreach($hopadditions as $hop)
{
$hopname = DB::table('hops')->where('id', $hop->hop_id)->first();
$hop['hop_name'] = $hopname->name;
};
$yeastadditions = Fermentation::where('beer_id', $beerID)->get();
foreach($yeastadditions as $yeast)
{
$yeastname = DB::table('yeasts')->where('id', $yeast->yeast_id)->first();
$yeast['yeast_name'] = $yeastname->name;
if($yeast->alternative) {
$altname = DB::table('yeasts')->where('id', $yeast->alternative)->value('name');
$yeast['altname'] = $altname;
}
};
$adjunctadditions = Adjunctaddition::where('beer_id', $beerID)->get();
foreach($adjunctadditions as $adjunct)
{
$adjunctname = DB::table('adjuncts')->where('id', $adjunct->adjunct_id)->first();
$adjunct['adjunct_name'] = $adjunctname->name;
};
$data = array('breweries'=>$breweries, 'beer'=>$beer, 'grainbills'=>$grainbills, 'mashsteps'=>$mashsteps, 'hopadditions'=>$hopadditions, 'adjunctadditions'=>$adjunctadditions, 'yeastadditions'=>$yeastadditions);
return view('beer')->with($data);
}
}