Browse Source

first iteration of search functionality - likely to fail hard

master
jk 3 years ago
parent
commit
f31a1edf66
  1. 37
      app/Http/Controllers/SearchController.php
  2. 6
      resources/views/search/results.blade.php

37
app/Http/Controllers/SearchController.php

@ -34,16 +34,21 @@ class SearchController extends Controller
$brewery = Brewerie::where('id', $result->brewery_id)->value('name'); $brewery = Brewerie::where('id', $result->brewery_id)->value('name');
$result['brewery']=$brewery; $result['brewery']=$brewery;
$hops = Hopaddition::where('beer_id', $result->beer_id)->distinct('hop_id'); $hops = Hopaddition::where('beer_id', $result->beer_id)->distinct('hop_id');
$result['hops']=[];
$hoparr=array();
$i = 0; $i = 0;
foreach ($hops as $hop){ 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++; $i++;
}; };
$result['hops']=$hoparr;
$grains = Grainbill::where('beer_id', $result->beer_id)->get(); $grains = Grainbill::where('beer_id', $result->beer_id)->get();
$grainarr = array(); $grainarr = array();
$i = 0;
foreach ($grains as $grain){ foreach ($grains as $grain){
$grainname = Grain::where('id', $grain->grain_id)->value('name'); $grainname = Grain::where('id', $grain->grain_id)->value('name');
if ($i == 0){ if ($i == 0){
@ -55,23 +60,31 @@ class SearchController extends Controller
}; };
$result['grains'] = $grainarr; $result['grains'] = $grainarr;
$yeasts = Fermentation::where('beer_id', $result->beer_id)->distinct('yeast_id'); $yeasts = Fermentation::where('beer_id', $result->beer_id)->distinct('yeast_id');
$result['yeasts']=[];
$yeastarr=array();
$i = 0; $i = 0;
foreach ($yeasts as $yeast){ 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++; $i++;
}; };
$result['yeasts']=$yeastarr;
$adjuncts = Adjunctaddition::where('beer_id', $result->beer_id)->distinct('adjunct_id'); $adjuncts = Adjunctaddition::where('beer_id', $result->beer_id)->distinct('adjunct_id');
$result['adjuncts']=[];
$adjunctarr = array();
$i = 0; $i = 0;
foreach ($adjuncts as $adjunct){ 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++; $i++;
}; };
$result['adjuncts']=$adjunctarr;
} }
break; break;
case('brewerie'): case('brewerie'):

6
resources/views/search/results.blade.php

@ -89,9 +89,9 @@
<tr> <tr>
<td><a href="/beer/{{$result->beer_id}}">{{$result->name}}</a> </td> <td><a href="/beer/{{$result->beer_id}}">{{$result->name}}</a> </td>
<td class="hideable">@foreach($result->grains as $grain)<a href="/grain/{{$grain['id']}}">{{$grain['name']}}</a><span style="float:right;">({{$grain['grain_bill']}}%)</span><br/> @endforeach</td> <td class="hideable">@foreach($result->grains as $grain)<a href="/grain/{{$grain['id']}}">{{$grain['name']}}</a><span style="float:right;">({{$grain['grain_bill']}}%)</span><br/> @endforeach</td>
<td class="hideable">Hops </td>
<td class="hideable">Yeasts </td>
<td class="hideable">Asjuncts </td>
<td class="hideable">@foreach($result->hops as $hop)<a href="/hop/{{$hop['id']}}">{{$hop['name']}}</a><br/>@endforeach </td>
<td class="hideable">@foreach($result->yeasts as $yeast)<a href="/yeast/{{$yeast['id']}}">{{$yeast['name']}}</a><br/>@endforeach </td>
<td class="hideable">@foreach($result->adjuncts as $adjunct)<a href="/adjunct/{{$adjunct['id']}}">{{$adjunct['name']}}</a><br/>@endforeach </td>
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>

Loading…
Cancel
Save