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.

39 lines
1.1 KiB

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