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.

40 lines
1.3 KiB

3 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Yeast;
  5. use App\Models\Fermentation;
  6. use Illuminate\Support\Facades\DB;
  7. class YeastcardController extends Controller
  8. {
  9. public function __construct()
  10. {
  11. $this->middleware('auth');
  12. }
  13. public function index($yeastID)
  14. {
  15. $yeast = DB::table('yeasts')->where('id', $yeastID)->first();
  16. $yeastadditions = Fermentation::where('yeast_id', $yeastID)->distinct('beer_id')->get();
  17. foreach ($yeastadditions as $yeasts)
  18. {
  19. $beerName = DB::table('summaries')->where('beer_id', $yeasts->beer_id)->value('name');
  20. $breweryID = DB::table('summaries')->where('beer_id', $yeasts->beer_id)->value('brewery_id');
  21. $breweryName = DB::table('breweries')->where('id', $breweryID)->value('name');
  22. if($yeasts->alternative) {
  23. $altname = DB::table('yeasts')->where('id', $yeasts->alternative)->value('name');
  24. $yeasts['altname']=$altname;
  25. }
  26. $yeasts['beer'] = $beerName;
  27. $yeasts['breweryID'] = $breweryID;
  28. $yeasts['brewery']=$breweryName;
  29. }
  30. $yeastadditions = $yeastadditions->sortBy('brewery');
  31. $data = array('yeast'=>$yeast, 'yeastadditions'=>$yeastadditions);
  32. return view('yeast')->with($data);
  33. }
  34. }