filtered_infos; $publishedRecipes = Recipe::when( isset($filters_activated), function ($query) use ($filters_activated) { if ($filters_activated[0] >= 0) { $diff_oper = '='; } else { $diff_oper = '>'; } if ($filters_activated[1] >= 0) { $min_time = PreparationTimeEnum::toArray()[$filters_activated[1]]->time['min']; $max_time = PreparationTimeEnum::toArray()[$filters_activated[1]]->time['max']; } else { $min_time = 0; $max_time = 9999; } if ($filters_activated[2] >= 0) { $cook_oper = '='; } else { $cook_oper = '>'; } $query->where('difficulty', $diff_oper, $filters_activated[0]) ->whereBetween('preparation_time', [$min_time, $max_time]) ->where('cooking_mode', $cook_oper, $filters_activated[2]); } ) ->where('status', true) ->orderBy('created_at') ->paginate(9); return view('fo.pages.recipes.index', compact('publishedRecipes', 'filters_activated')); } /** * Return a view with a specific model. * * @param \App\Models\Recipe $publishedRecipe * @return \Illuminate\Contracts\View\View */ public function show(Recipe $publishedRecipe) { $products = $publishedRecipe->products()->get(); $relatedRecipes = $publishedRecipe->recipes()->where('status', true)->get(); // 3 Recettes. $publishedRecipes = Recipe::where('status', true) ->where('id', '!=', $publishedRecipe->id) ->take(3) ->get(); $recipeModel = $publishedRecipe; return view( 'fo.pages.recipes.recipe', compact('recipeModel', 'products', 'relatedRecipes') ); } }