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.1 KiB

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