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.

36 lines
1.2 KiB

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