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::from($filters_activated[1])->time()['min']; $max_time = PreparationTimeEnum::from($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') ); } /** * Print recipe informations * * @param \App\Models\Recipe $publishedRecipe * @return \Symfony\Component\HttpFoundation\Response * @return void */ public function printRecipe(Recipe $publishedRecipe): \Symfony\Component\HttpFoundation\Response { $title = trans('Fiche commerciale du produit : :label - :appname', [ 'label' => $publishedRecipe->name, 'appname' => \config('app.name', 'Lionor') ]); $filename = trans('fiche-commerciale-:slug-:date', [ 'slug' => Str::slug($publishedRecipe->name), 'date' => \now()->format('Y-m-d') ]); return $this->generateRecipePdf($publishedRecipe, $title) ->stream("docrecipe.pdf"); } /** * Generate recipe PDF * * @param \App\Models\Recipe $recipe * @param string $title * @return \Mccarlosen\LaravelMpdf\LaravelMpdf */ private function generateRecipePdf(Recipe $recipe, string $title): \Mccarlosen\LaravelMpdf\LaravelMpdf { $tabRecipe = \json_decode(\json_encode(new RecipeResource($recipe))); /** @var \Mccarlosen\LaravelMpdf\LaravelMpdf */ $mpdf = app('laravel-mpdf'); /** @var \Mccarlosen\LaravelMpdf\LaravelMpdf */ $pdf = $mpdf->loadView( 'fo.documents.recipe', // * Dirty convert to object. [ 'title' => $title, 'recipe' => $tabRecipe ], [], [ 'mode' => 'utf-8', 'format' => 'A4', 'default_font_size' => '12', 'default_font' => 'sans-serif', // Recto Verso. 'margin_left' => 10, 'margin_right' => 10, 'mirrorMargins' => true, 'margin_top' => 25, 'margin_bottom' => 20, 'margin_header' => 0, 'margin_footer' => 0, 'orientation' => 'P', 'title' => $title, 'author' => \config('app.name', 'Lionor'), 'watermark' => '', 'show_watermark' => false, 'watermark_font' => 'sans-serif', 'display_mode' => 'fullpage', 'watermark_text_alpha' => 0.1, 'custom_font_dir' => '', 'custom_font_data' => [], 'auto_language_detection' => false, 'temp_dir' => rtrim( ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir(), DIRECTORY_SEPARATOR ), 'pdfa' => false, 'pdfaauto' => false, ] ); return $pdf; } }