validate($request,[ 'search' => 'required', 'table' => 'required', ]); $search = $request->input('search'); $table = $request->input('table'); switch($table) { case('summarie'): $results = Summarie::where('keywords', 'LIKE', '%'.$search.'%')->orWhere('type', 'LIKE', '%'.$search.'%')->sortable()->paginate(10); foreach ($results as $result) { $brewery = Brewerie::where('id', $result->brewery_id)->value('name'); $result['brewery']=$brewery; $hops = Hopaddition::where('beer_id', $result->beer_id)->distinct('hop_id'); $hoparr=array(); $i = 0; foreach ($hops as $hop){ $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){ $grainarr[]= array('id'=>$grain->grain_id, 'name'=>$grainname, 'grain_bill'=>$grain->grain_bill); } else { array_push($grainarr, array('id'=>$grain->grain_id, 'name'=>$grainname, 'grain_bill'=>$grain->grain_bill)); }; $i++; }; $result['grains'] = $grainarr; $yeasts = Fermentation::where('beer_id', $result->beer_id)->distinct('yeast_id'); $yeastarr=array(); $i = 0; foreach ($yeasts as $yeast){ $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'); $adjunctarr = array(); $i = 0; foreach ($adjuncts as $adjunct){ $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'): break; case('hops'): break; case('yeast'): break; default: $msg = "You fucked up somehow!"; } $data = array('results'=>$results, 'table'=>$table); return view('search.results')->with($data); } }