diff options
| author | horus | 2022-09-25 03:51:14 +0200 |
|---|---|---|
| committer | horus | 2022-09-25 03:51:14 +0200 |
| commit | 6b59ee2a6427431a1d5e76bf70f8c5e97b10eb3e (patch) | |
| tree | abb07501bd6305fa2a5f3a0242d5242b16d5aa9a /app/Http/Controllers | |
| parent | acbe243bcd4c2dade2a834ce6bdedf46d1d10ae2 (diff) | |
| download | kategorischeraperitif-6b59ee2a6427431a1d5e76bf70f8c5e97b10eb3e.tar.gz | |
Verodern der Zutaten möglich.
Diffstat (limited to 'app/Http/Controllers')
| -rw-r--r-- | app/Http/Controllers/CocktailController.php | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/app/Http/Controllers/CocktailController.php b/app/Http/Controllers/CocktailController.php index ef24ab8..117f490 100644 --- a/app/Http/Controllers/CocktailController.php +++ b/app/Http/Controllers/CocktailController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Str; use App\Cocktail; use App\Ingredient; @@ -33,7 +34,7 @@ class CocktailController extends Controller } $excludes = $request->input("i_ex"); if ( ! isset($excludes) || empty($excludes) ) { - $excludes = array(); + $excludes = array(""); } $cocktails = new Cocktail; @@ -42,25 +43,38 @@ class CocktailController extends Controller $q = Helper::escapeLike($q); $q = "%".$q."%"; - if ( ! isset($excludes) || empty($excludes) ) { - $cocktails = $cocktails->where(function($query) use ($q){ + foreach($excludes as $ex) { + $ex = Helper::escapeLike($ex); + $ex = "%".$ex."%"; + + $cocktails = $cocktails->where(function($query) use ($q, $ex){ $query->whereHas("getIngredients", function ($query) use ($q){ - $query->where('name', 'like', $q); + if ( Str::contains($q, '$or$') ) { + $exploded = explode('$or$', $q); + $query->where( function ($query) use ($exploded){ + foreach($exploded as $e) + $query->orWhere('name', 'like', $e); + }); + } else { + $query->where('name', 'like', $q); + } }); + if ( "%%" != $ex ) { + $query->whereDoesntHave("getIngredients", function ($query) use ($ex){ + $query->where('name', 'like', $ex); + }); + } }); - } else { - foreach($excludes as $ex) { - $ex = Helper::escapeLike($ex); - $ex = "%".$ex."%"; - - $cocktails = $cocktails->where(function($query) use ($q, $ex){ - $query->whereHas("getIngredients", function ($query) use ($q){ - $query->where('name', 'like', $q); - })->whereDoesntHave("getIngredients", function ($query) use ($ex){ - $query->where('name', 'like', $ex); - }); - }); - } + } + } + + foreach($ingredients as $key => $q) { + if ( Str::contains($q, '$or$') ) { + unset($ingredients[$key]); + $exploded = explode('$or$', $q); + foreach($exploded as $key => $val ) + $exploded[$key] = trim($exploded[$key] ); + $ingredients = array_merge($ingredients, $exploded); } } @@ -84,8 +98,10 @@ class CocktailController extends Controller $exclude_phrase = rtrim($exclude_phrase, " und "); } - $search_phrase .= " und nicht nach " . $exclude_phrase; + 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) ]); |
