diff options
| author | horus | 2022-09-25 04:24:12 +0200 |
|---|---|---|
| committer | horus | 2022-09-25 04:24:12 +0200 |
| commit | 0b7c0878c1d886d001fd46c8c5a75188153a762a (patch) | |
| tree | 141cceb89cd42e9918335a3133b4190ab433d437 /app/Http/Controllers/CocktailController.php | |
| parent | 6b59ee2a6427431a1d5e76bf70f8c5e97b10eb3e (diff) | |
| download | kategorischeraperitif-0b7c0878c1d886d001fd46c8c5a75188153a762a.tar.gz | |
Hübsche Veroderung und Redirect.
Diffstat (limited to 'app/Http/Controllers/CocktailController.php')
| -rw-r--r-- | app/Http/Controllers/CocktailController.php | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/app/Http/Controllers/CocktailController.php b/app/Http/Controllers/CocktailController.php index 117f490..9c5f096 100644 --- a/app/Http/Controllers/CocktailController.php +++ b/app/Http/Controllers/CocktailController.php @@ -14,8 +14,16 @@ use App\Libraries\Helper; class CocktailController extends Controller { - public function index() + public function index(Request $request) { + /** + * shorthand + */ + $input = $request->input("q"); + if ( isset($input) && "" != $input ){ + return redirect()->route('cocktail_search', ['i[]' => $input ]); + } + if ( Cache::has('cocktail_count') ) { $cocktail_count= Cache::get('cocktail_count'); } else { @@ -40,8 +48,6 @@ class CocktailController extends Controller $cocktails = new Cocktail; foreach($ingredients as $q) { - $q = Helper::escapeLike($q); - $q = "%".$q."%"; foreach($excludes as $ex) { $ex = Helper::escapeLike($ex); @@ -49,13 +55,18 @@ class CocktailController extends Controller $cocktails = $cocktails->where(function($query) use ($q, $ex){ $query->whereHas("getIngredients", function ($query) use ($q){ - if ( Str::contains($q, '$or$') ) { - $exploded = explode('$or$', $q); + if ( Str::contains($q, ' oder ') ) { + $exploded = explode(' oder ', $q); $query->where( function ($query) use ($exploded){ - foreach($exploded as $e) + foreach($exploded as $e) { + $e = Helper::escapeLike($e); + $e = "%".$e."%"; $query->orWhere('name', 'like', $e); + } }); } else { + $q = Helper::escapeLike($q); + $q = "%".$q."%"; $query->where('name', 'like', $q); } }); @@ -69,9 +80,9 @@ class CocktailController extends Controller } foreach($ingredients as $key => $q) { - if ( Str::contains($q, '$or$') ) { + if ( Str::contains($q, ' oder ') ) { unset($ingredients[$key]); - $exploded = explode('$or$', $q); + $exploded = explode(' oder ', $q); foreach($exploded as $key => $val ) $exploded[$key] = trim($exploded[$key] ); $ingredients = array_merge($ingredients, $exploded); @@ -101,8 +112,6 @@ class CocktailController extends Controller if ( "" != $exclude_phrase) $search_phrase .= " und nicht nach " . $exclude_phrase; - #var_dump( array_filter($ingredients));exit; - return view('cocktail_list', [ "cocktails" => $cocktails, "count" => $count, "search_terms" => array_filter($ingredients), "search_phrase" => $search_phrase, "exclude_terms" => array_filter($excludes) ]); } |
