diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index bd4c2d1..ec104e3 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -34,16 +34,21 @@ class SearchController extends Controller $brewery = Brewerie::where('id', $result->brewery_id)->value('name'); $result['brewery']=$brewery; $hops = Hopaddition::where('beer_id', $result->beer_id)->distinct('hop_id'); - $result['hops']=[]; + $hoparr=array(); $i = 0; foreach ($hops as $hop){ - $hopname = Hop::where('id', $hop->id)->value('name'); - $result['hops'][$i]['id'] = $hop->id; - $result['hops'][$i]['name'] = $hopname; + $hopname = Hop::where('id', $hop->hop_id)->value('name'); + if ($i == 0){ + $hoparr[]= array('id'=>$hop->hop_id, 'name'=>$hopname); + } else { + array_push($hoparr, array('id'=>$hop->hop_id, 'name'=>$hopname)); + }; $i++; }; + $result['hops']=$hoparr; $grains = Grainbill::where('beer_id', $result->beer_id)->get(); $grainarr = array(); + $i = 0; foreach ($grains as $grain){ $grainname = Grain::where('id', $grain->grain_id)->value('name'); if ($i == 0){ @@ -55,23 +60,31 @@ class SearchController extends Controller }; $result['grains'] = $grainarr; $yeasts = Fermentation::where('beer_id', $result->beer_id)->distinct('yeast_id'); - $result['yeasts']=[]; + $yeastarr=array(); $i = 0; foreach ($yeasts as $yeast){ - $yeastname = Yeast::where('id', $yeast->id)->value('name'); - $result['yeasts'][$i]['id'] = $yeast->id; - $result['yeasts'][$i]['name'] = $yeastname; + $yeastname = Yeast::where('id', $yeast->yeast_id)->value('name'); + if ($i == 0){ + $yeastarr[]= array('id'=>$yeast->yeast_id, 'name'=>$yeastname); + } else { + array_push($yeastarr, array('id'=>$yeast->yeast_id, 'name'=>$yeastnname)); + }; $i++; }; + $result['yeasts']=$yeastarr; $adjuncts = Adjunctaddition::where('beer_id', $result->beer_id)->distinct('adjunct_id'); - $result['adjuncts']=[]; + $adjunctarr = array(); $i = 0; foreach ($adjuncts as $adjunct){ - $adjunctname = Adjunct::where('id', $adjunct->id)->value('name'); - $result['adjuncts'][$i]['id'] = $adjunct->id; - $result['adjuncts'][$i]['name'] = $adjunctname; + $adjunctname = Adjunct::where('id', $adjunct->adjunct_id)->value('name'); + if ($i == 0){ + $adjunctarr[]= array('id'=>$adjunct->adjunct_id, 'name'=>$adjunctname); + } else { + array_push($adjunctarr, array('id'=>$adjunct->adjunct_id, 'name'=>$adjunctnname)); + }; $i++; }; + $result['adjuncts']=$adjunctarr; } break; case('brewerie'): diff --git a/resources/views/search/results.blade.php b/resources/views/search/results.blade.php index 0b1c577..c12d222 100644 --- a/resources/views/search/results.blade.php +++ b/resources/views/search/results.blade.php @@ -89,9 +89,9 @@